js中for循环的问题
今天过来加班,运行了一下以前写的代码,竟然有问题,出错的地方是由于一段js代码引起的:
1
string scriptA = @"
2
<script>
3
var s ;
4
var sNun ;
5
var controlNum ;
6
var chkother= document.getElementsByTagName('input');
7
for (var i=0;i<chkother.length;i++)
8
{
9
if( chkother[i].type=='submit')
10
{
11
if(chkother[i].id.indexOf('btnSubmit')>-1)
12
{
13
14
s = chkother[i].id.split('_');
15
controlNum = s[s.length-1] ;
16
break ;
17
}
18
}
19
} ";
20
if( ViewState["PersonType"].ToString() != "" )
21
{
22
scriptA += @" var controlUserId = 'userName_'+s[s.length-1]+'_Value1' ;
23
var userIdValue = document.all['AppOpinion_list1_'+controlUserId].value ;
24
document.all.AppOpinion_list1_hiddMan.value = userIdValue; ";
25
}
26
27
scriptA += @" var controlRaesonId = 'txtOPinion_'+s[s.length-1];
28
var reasonValue = document.all['AppOpinion_list1_'+controlRaesonId].value ;
29
document.all.AppOpinion_list1_hiddoValue.value = reasonValue;
30
31
var j =0;
32
for (var i=0;i<chkother.length;i++)
33
{
34
if(chkother[i].id.indexOf('AppOpinion_list1_radiobtnResule_'+s[s.length-1])>-1)
35
{
36
j++;
37
if( chkother[i].checked )
38
{
39
sNun = j ;
40
}
41
}
42
}
43
document.all.AppOpinion_list1_hiddResult.value = sNun;
44
document.all.AppOpinion_list1_btnInsertFlow.click();
45
</script>";
46
Page.RegisterStartupScript("EA",scriptA);
string scriptA = @"2
<script>3
var s ;4
var sNun ;5
var controlNum ;6
var chkother= document.getElementsByTagName('input');7
for (var i=0;i<chkother.length;i++)8
{9
if( chkother[i].type=='submit')10
{11
if(chkother[i].id.indexOf('btnSubmit')>-1)12
{13
14
s = chkother[i].id.split('_'); 15
controlNum = s[s.length-1] ;16
break ;17
}18
}19
} ";20
if( ViewState["PersonType"].ToString() != "" )21
{22
scriptA += @" var controlUserId = 'userName_'+s[s.length-1]+'_Value1' ;23
var userIdValue = document.all['AppOpinion_list1_'+controlUserId].value ;24
document.all.AppOpinion_list1_hiddMan.value = userIdValue; ";25
}26
27
scriptA += @" var controlRaesonId = 'txtOPinion_'+s[s.length-1]; 28
var reasonValue = document.all['AppOpinion_list1_'+controlRaesonId].value ;29
document.all.AppOpinion_list1_hiddoValue.value = reasonValue;30
31
var j =0;32
for (var i=0;i<chkother.length;i++)33
{34
if(chkother[i].id.indexOf('AppOpinion_list1_radiobtnResule_'+s[s.length-1])>-1)35
{36
j++;37
if( chkother[i].checked )38
{39
sNun = j ;40
}41
}42
}43
document.all.AppOpinion_list1_hiddResult.value = sNun;44
document.all.AppOpinion_list1_btnInsertFlow.click();45
</script>";46
Page.RegisterStartupScript("EA",scriptA);在for循环中没有增加break的时候,s[s.length-1]的值在先后的调用中会不同,这点就比较郁闷


浙公网安备 33010602011771号