The CheckBox control indicates whether a particular state (that is, an option) is selected (on, the value is 1) or cleared (off, with a value of 0). Use this control in your application to provide users with a choice of "true/false" or "yes/no". Because the checkbox works independently of each other, the user can select as many checkbox as possible to combine options.
CheckBox check box JS implementation of the full selection, not selected, all the optional function, very simple, the specific content as follows
Ideas:
- 1. Get the Element
- 2. Add Click events to select all optional options
- 3, with For loop checkbox
- 4, the checkbox checked set to True to achieve the full selection
- 5, the checkbox checked set to False to achieve the optional
- 6, if the judge, if checked is true selected state, the checked set to False state, if checked false state, the checked set to true selected state.
HTML code:
<input type=" button "value=" Select All "id=" Sele "/> <input type=" button "value=" Do not select "Id=" se Tinterval "/> <input type=" button "value=" anti-select "id=" clear "/> <div" id= "Checkboxs" > <input type= "che
Ckbox "/><br/> <input type=" checkbox "/><br/>" checkbox "<input type= <input type= "checkbox"/><br/> <input type= checkbox/><br/> <input type= "checkbox"/&G t;<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 "ch Eckbox "/><br/> <input type=" checkbox "/><br/>" <input type= "checkbox"/><br ;/div>
JS Code:
<script>
window.onload=function () {
var Sele=document.getelementbyid (' Sele ');//Get Select all
var unsele= document.getElementById (' setinterval '); get select Var
clear=document.getelementbyid (' clear ');//Get Inverse
var Checkbox=document.getelementbyid (' Checkboxs ');//Get Div
var checked=checkbox.getelementsbytagname (' input '); Gets the input
//Select All
sele.onclick=function () {for
(i=0;i<checked.length;i++) {
checked[i] under the div. Checked=true
}
//Do not select
unsele.onclick=function () {for
(i=0;i<checked.length;i++) {
checked[i].checked=false
}
}
Reverse-Select
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>
The above mentioned is the entire content of this article, I hope you can enjoy.