- <html>
- <body>
- <script language="javascript">
- function check(field,obj) {
- var div=field;
- var ckb=document.getElementsByTagName("INPUT");
- if(obj.checked)
- {
- for(i=0;i<ckb.length;i++)
- {
- if(ckb[i].parentNode==div && ckb[i].type=="checkbox")
- ckb[i].checked=true;
- }
- }
- else
- {
- for(i=0;i<ckb.length;i++)
- {
- if(ckb[i].parentNode==div && ckb[i].type=="checkbox")
- ckb[i].checked=false;
- }
- }
- }
- </script>
- <form name=myform action="" method=post>
- <b>请选择下面的选项</b><br>
- <div id="div1">
- <input type=checkbox name=list2 onClick="this.value=check(div1,this)" value="0">全选<br>
- <input type=checkbox name=list value="1">Java<br>
- <input type=checkbox name=list value="2">JavaScript<br>
- <input type=checkbox name=list value="3">ASP<br>
- <input type=checkbox name=list value="4">HTML<br>
- <input type=checkbox name=list value="5">SQL<br>
- </div>
- <p></p>
- <div id="div2">
- <input type=checkbox name=list2 onClick="this.value=check(div2,this)" value="0">全选<br>
- <input type=checkbox name=list3 value="1">Java<br>
- <input type=checkbox name=list3 value="2">JavaScript<br>
- <input type=checkbox name=list3 value="3">ASP<br>
- <input type=checkbox name=list3 value="4">HTML<br>
- <input type=checkbox name=list3 value="5">SQL<br>
- </div>
- </form>
- </body>
- </html>
选中div中的全部checkbox
最新推荐文章于 2021-12-08 00:47:40 发布