CheckBox控件表明一个特定的状态(即选项)是选定 (on,值为1) 还是清除 (off,值为0)。在应用程序中使用该控件为用户提供“True/False”或“yes/no”的选择。因为 CheckBox 彼此独立工作,所以用户可以同时选择任意多个 CheckBox,进行选项组合。
CheckBox复选框JS实现全选、不选、全不选功能,很简单,具体内容如下
思路:
html代码:
<input type=\"button\" value=\"全选\" id=\"sele\"/> <input type=\"button\" value=\"不选\" id=\"setinterval\"/> <input type=\"button\" value=\"反选\" id=\"clear\"/> <div id=\"checkboxs\"> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> <input type=\"checkbox\"/><br /> </div>
js代码:
<script> window.onload=function(){ var sele=document.getElementById(\'sele\');//获取全选 var unsele=document.getElementById(\'setinterval\');//获取不选 var clear=document.getElementById(\'clear\');//获取反选 var checkbox=document.getElementById(\'checkboxs\');//获取div var checked=checkbox.getElementsByTagName(\'input\');//获取div下的input //全选 sele.onclick=function(){ for(i=0;i<checked.length;i++){ checked[i].checked=true } } //不选 unsele.onclick=function(){ for(i=0;i<checked.length;i++){ checked[i].checked=false } } //反选 clear.onclick=function(){ for(i=0;i<checked.length;i++){ if(checked[i].checked==true){ checked[i].checked=false } else{ checked[i].checked=true } } } } </script>
以上所述就是本文的全部内容了,希望大家能够喜欢。
本文地址:https://www.stayed.cn/item/21451
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我