DataGrid1__ctl4_chkSelect
             -这是地方是字母 l 而不是数字 1 , L4%2 !=0 当然永远成立喽

解决方案 »

  1.   

    这位大哥,不要拿l 当1 用,不一样的
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <script language="JAVASCRIPT">
    function AddRemoveValues(oChk) { 
    bgColor = "FEEEE0";
    if(oChk.checked)
    {
    alert("in");
    }
    else
    {
    var countId= oChk.id.substring(13,15);
    alert(parseInt(countId));
    if(parseInt(countId)%2!= 0)
    {
    alert("nihao");
    }
    else
    {
    alert("buhao");
    }}
    //alert(frmAreaSearch.HdnSelectedValues.value);
    }
     
    </script>
    <body bgcolor="#FFFFFF" text="#000000">
    <form name="frmAreaSearch" method="post" action="" id="frmAreaSearch">
    <table class="012" cellspacing="0" rules="all" bordercolor="White" border="1" id="DataGrid1" style="border-color:White;border-width:1px;border-style:solid;width:100%;border-collapse:collapse;">
      <tr style="background-color:#BBD9F0;"> 
        <td style="width:4%;">选择</td>
        
      </tr>
      <tr> 
        <td> 
          <input name="DataGrid1:_ct12:chkSelect" id="DataGrid1__ct12_chkSelect" type="checkbox" onclick="AddRemoveValues(this)" value="19" />
        </td>
      </tr>
      <tr style="background-color:WhiteSmoke;"> 
        <td> 
          <input name="DataGrid1:_ct13:chkSelect" id="DataGrid1__ct13_chkSelect" type="checkbox" onclick="AddRemoveValues(this)" value="18" />
        </td>
      </tr>
      <tr> 
        <td> 
          <input name="DataGrid1:_ct14:chkSelect" id="DataGrid1__ct14_chkSelect" type="checkbox" onclick="AddRemoveValues(this)" value="17" />
        </td>
      </tr>
    </table></form>
    </body>
    </html>
      

  2.   

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <script language="JAVASCRIPT">
    function AddRemoveValues(oChk) { 
    bgColor = "FEEEE0";
    if(oChk.checked)
    {
    alert("in");
    }
    else
    {
    var countId= oChk.id.substring(14,15)+0;
    alert(countId);
    if(countId%2!= 0)
    {
    alert("nihao");
    }
    else
    {
    alert("buhao");
    }}
    //alert(frmAreaSearch.HdnSelectedValues.value);
    }
     
    </script>
    <body bgcolor="#FFFFFF" text="#000000">
    <form name="frmAreaSearch" method="post" action="" id="frmAreaSearch">
    <table class="012" cellspacing="0" rules="all" bordercolor="White" border="1" id="DataGrid1" style="border-color:White;border-width:1px;border-style:solid;width:100%;border-collapse:collapse;">
      <tr style="background-color:#BBD9F0;"> 
        <td style="width:4%;">选择</td>
        
      </tr>
      <tr> 
        <td> 
          <input name="DataGrid1:_ctl2:chkSelect" id="DataGrid1__ctl2_chkSelect" type="checkbox" onclick="AddRemoveValues(this)" value="19" />
        </td>
      </tr>
      <tr style="background-color:WhiteSmoke;"> 
        <td> 
          <input name="DataGrid1:_ctl3:chkSelect" id="DataGrid1__ctl3_chkSelect" type="checkbox" onclick="AddRemoveValues(this)" value="18" />
        </td>
      </tr>
      <tr> 
        <td> 
          <input name="DataGrid1:_ctl4:chkSelect" id="DataGrid1__ctl4_chkSelect" type="checkbox" onclick="AddRemoveValues(this)" value="17" />
        </td>
      </tr>
    </table></form>
    </body>
    </html>
      

  3.   

    你用 substring 取这个数字时会出错的, 当数字大于10之后就是两位数字了, 所以这里用个正则吧
      var countId= oChk.id.match(/_ctl\d+_/g)[0].replace(/[_a-z]/gi, "");