onclick是不行的,因为我可能通过点击其他checkbox将另外的选中,只能通过状态改变事件控制了。

解决方案 »

  1.   

    <script language="JavaScript1.2">
    function check_all(form,checked){
    for (i=0;i<form.length;i++)
    {
    if (form.elements[i].type=='checkbox')
    form.elements[i].checked=(checked==true?true:false);
    }
    }
    </script>
    </head><body>
    <form name="form1" method="post" action="">
      <input type="checkbox" name="checkbox" value="checkbox" onClick="check_all(this.form,checkbox.checked);">
      <table width="75%" border="1">
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="checkbox2" value="checkbox" onChange="alert('sdf');"  ></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="checkbox3" value="checkbox" onChange="alert('sdf');"></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="checkbox4" value="checkbox" onChange="alert('sdf');"></td>
          <td>&nbsp;</td>
        </tr>
      </table>
    </form>
    onchange怎么没有触发呢?
      

  2.   

    <input type=checkbox onclick="document.all.checkson.checked=this.checked;document.all.checkson.value=document.all.checkson.checked?1:0">父项
    <input type=checkbox id=checkson value=0 disabled>子项
    <input type=button value=getSonValue onclick=alert(document.all.checkson.value)>
      

  3.   

    thank you, : seabell(百合心)马上揭贴,不过还想问个问题,就是当状态改变时checkbox出发什么事件,能捕捉吗?
      

  4.   

    我刚才试了一下,通过代码来改变checkbox状态时,onchange也不触发。sorry我就不知道了