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。。。
  • 相关阅读:
    周末之个人杂想(十三)
    PowerTip of the DaySorting Multiple Properties
    PowerTip of the DayCreate Remoting Solutions
    PowerTip of the DayAdd Help to Your Functions
    PowerTip of the DayAcessing Function Parameters by Type
    PowerTip of the DayReplace Text in Files
    PowerTip of the DayAdding Extra Information
    PowerTip of the DayPrinting Results
    Win7下IIS 7.5配置SSAS(2008)远程访问
    PowerTip of the DayOpening Current Folder in Explorer
  • 原文地址:https://www.cnblogs.com/oldhorse/p/564396.html
Copyright © 2011-2022 走看看