如何实现复选框的全选、全不选、反选

<html> <head><title>复选框的全选、全不选、反选</title></head> <body> <form mehod="post" action="" name="selectForm"> <input type="checkbox" name="cc" value="c" onClick="allSelect()" />全选<br> <input type="checkbox" name="c" value="c1" />c1<br> <input type="checkbox" name="c" value="c2" />c2<br> <input type="checkbox" name="c" value="c3" />c3<br> <input type="checkbox" name="c" value="c4" />c4<br> <input type="checkbox" name="c" value="c5" />c5<br> <input type="checkbox" name="c" value="c6" />c6<br> <p> <a href="#" onClick="allSelect()">全选</a>// <a href="#" onClick="noneSelect()">全不选</a>// <a href="#" onClick="oppositeSelect()">反选</a> </p> <p> <input type="button" onClick="allSelect()" value="全选" /> <input type="button" onClick="noneSelect()" value="全不选" /> <input type="button" onClick="oppositeSelect()" value="反选" /> </p> </form> <script type="text/javascript"> var cc = document.getElementsByName("c"); function allSelect(){ for(i=0; i<cc.length; i++){ if(cc[i].type="checkbox"){ cc[i].checked = true; } } } function noneSelect(){ for(i=0; i<cc.length; i++){ if(cc[i].type="checkbox"){ cc[i].checked = false; } } } function oppositeSelect(){ for(i=0; i<cc.length; i++){ if(cc[i].type="checkbox"){ cc[i].checked = (cc[i].checked)?false:true; } } } </script> <script language="javascript"> function chk() { var dd = document.getElementsByTagName("input") for(i=0;i <dd.length;i++) { if(dd[i].type== 'checkbox' && dd[i].id != "xx"){ dd[i].checked = document.getElementById("xx").checked; } } } </script> <input type="checkbox" name="checkbox0" id="xx" value="checkbox" onclick="chk()" /> 1<input type="checkbox" name="checkbox1" value="checkbox" /> 2<input type="checkbox" name="checkbox2" value="checkbox" /> 3<input type="checkbox" name="checkbox3" value="checkbox" /> 4<input type="checkbox" name="checkbox4" value="checkbox" /> 5<input type="checkbox" name="checkbox5" value="checkbox" /> 6<input type="checkbox" name="checkbox6" value="checkbox" /> </body> </html>

你可能感兴趣的:(JavaScript,c,function,input,action,button)