javascript 表单中checkbox全选
我是初学者
想要做一个js功能像邮箱中收件箱的复选框选全选会全部选中,在复选框全选中是第一个全选也打勾,在点就全取消
全选时有一个取消选中是第一个全选的勾也没了,
checkbox中的name的要值不一样
急~~谢谢帮忙~~~~
<script language= "JavaScript "> ????? </script>
<form name= 'f1 ' id= 'f1 '>
<input name= "allcheckbox " type= "checkbox " title= '全选/取消 ' onclick= "cball() "> 全选 <br>
<input name= "m1 " type= "checkbox " onclick= ' '> <br>
<input name= "m2 " type= "checkbox " onclick= ' '> <br>
<input name= "m3 " type= "checkbox " onclick= ' '> <br>
<input name= "m4 " type= "checkbox " onclick= ' '> <br>
<input name= "m5 " type= "checkbox " onclick= ' '> <br>
<input name= "m6 " type= "checkbox " onclick= ' '> <br>
</form>
------解决方案-------------------- <body>
<script language= "javascript ">
function cball(){
var oform=document.getElementById( "f1 ");
var oc=oform.childNodes;
//alert(oc.length);
for (i=0;i <oc.length;i++){
if ((oc(i).type)== "checkbox ")
oc(i).checked=(document.getElementById( "all ").checked?true:false);
//oc(i).checked=true;
}
}
function cnall(obj){
var oc=document.getElementById( "all ");
if (obj.checked==false)
oc.checked=false;
}
</script>
<form name= 'f1 ' id= 'f1 '>
<input id= "all " name= "allcheckbox " type= "checkbox " title= '全选/取消 ' onclick= "cball() "> 全选 <br/>
<input name= "m1 " type= "checkbox " onclick= 'cnall(this) '> <br/>
<input name= "m2 " type= "checkbox " onclick= 'cnall(this) '> <br/>
<input name= "m3 " type= "checkbox " onclick= 'cnall(this) '> <br/>
<input name= "m4 " type= "checkbox " onclick= 'cnall(this) '> <br/>
<input name= "m5 " type= "checkbox " onclick= 'cnall(this) '> <br/>
<input name= "m6 " type= "checkbox " onclick= 'cnall(this) '> <br/>
</form>
</body>