<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title></head><body><table>
<tr>
<td><input type="checkbox" name="checks"><input type="hidden" name="hids" value="0"></td>
<td><input type="text" name="t" value="aaaaa"></td>
</tr>
<tr>
<td><input type="checkbox" name="checks"><input type="hidden" name="his" value="0"></td>
<td><input type="text" name="t" value="bbb"></td>
</tr>
</table><script language="javascript">
var checks = document.getElementsByName("checks");
for(var i=0; i<checks.length; i++){
checks[i].onclick = function(){
if (this.checked){
this.nextSibling.value = 1;
}else{
this.nextSibling.value = 0;
}
}
}
</script>
</body>
</html>

解决方案 »

  1.   

    <script language="javascript">function changeValues(a){
    if(a.checked){ a.parentNode.childNodes[1].value='1'
      }else{  a.parentNode.childNodes[1].value='0'
      }  alert(document.getElementById("hids").value)
    }
    </script>
    <table>
    //下面的<tr>...</tr>是循?取的,多少不定.相同控件里面的name都相同
    <tr>
    <td><input type="checkbox" name="checks" onclick="changeValues(this)"><input type="hidden" name="hids" value="0"></td>
    <td><input type="text" name="t" value="aaaaa"></td>
    </tr>
    <tr>
    <td><input type="checkbox" name="checks" onclick="changeValues(this)"><input type="hidden" name="his" value="0"></td>
    <td><input type="text" name="t" value="bbb"></td>
    </tr>
    </table>
      

  2.   

    function hids(){
    var trs=document.getElementById("t").getElementsByTagName("tr");
    for(var i=0;i<trs.length;i++){
    var ins=trs[i].getElementsByTagName("input");
    ins[0].hi=ins[1];
    ins[0].te=ins[2];
    ins[0].onclick=function(){
    if(this.checked==true){
    this.hi.value=1;
    this.te.value="hidden的值为1";
    }else{
    this.hi.value=0;
    this.te.value="hidden的值为0";
    }
    }
    }
    }
    window.onload=hids;
    </script>
    <table id="t"><tr>
         <td><input type="checkbox" name="checks"><input type="hidden" name="hids" value="0"></td>
         <td><input type="text" name="hidsname" value="aaaaa"></td>
      </tr>
    <tr>
         <td><input type="checkbox" name="checks"><input type="hidden" name="his" value="0"></td>
       <td><input type="text" name="hisname" value="bbb"></td>
      </tr>
     </table>
      

  3.   

    上面少了一行
    <script type="text/javascript">
    function hids(){
    var trs=document.getElementById("t").getElementsByTagName("tr");
    for(var i=0;i<trs.length;i++){
    var ins=trs[i].getElementsByTagName("input");
    ins[0].hi=ins[1];
    ins[0].te=ins[2];
    ins[0].onclick=function(){
    if(this.checked==true){
    this.hi.value=1;
    this.te.value="hidden的值为1";
    }else{
    this.hi.value=0;
    this.te.value="hidden的值为0";
    }
    }
    }
    }
    window.onload=hids;
    </script>
    <table id="t"><tr>
         <td><input type="checkbox" name="checks"><input type="hidden" name="hids" value="0"></td>
         <td><input type="text" name="hidsname" value="aaaaa"></td>
      </tr>
    <tr>
         <td><input type="checkbox" name="checks"><input type="hidden" name="his" value="0"></td>
       <td><input type="text" name="hisname" value="bbb"></td>
      </tr>
     </table>