zoukankan      html  css  js  c++  java
  • js中for循环的问题

        今天过来加班,运行了一下以前写的代码,竟然有问题,出错的地方是由于一段js代码引起的:
        

     1string 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]的值在先后的调用中会不同,这点就比较郁闷,增加break语句跳出循环,就不会存在该问题,值的改变也只是在if语句中,而且确认一个数据符合if语句,虽然问题解决了,但是还不知道原因,以后在找找原因了,mark。。。
  • 相关阅读:
    (转)Computer Vision Open Source Algorithm Implementations
    关于项目依赖项
    fatal error CVT1100: duplicate resource. type:MANIFEST, name:1, language:0×0409
    转:error LNK2005
    C++ string类常用函数
    [转载]同步synchronized方法和代码块
    Java语言基础常用对象API(二)泛型、Map集合
    Java语言基础IO流(输入输出流) 字符流
    Java语言基础常用对象API(二)集合框架
    Java语言基础IO流(输入输出流) 字节流、转换流
  • 原文地址:https://www.cnblogs.com/oldhorse/p/564396.html
Copyright © 2011-2022 走看看