This paper illustrates the method of selecting, selecting and selecting the checkbox. Share to everyone for your reference. The specific analysis is as follows:
First, the idea:
1. Get element
2. Add Click events to select all optional options
3. Use for loop checkbox
4. Set the checkbox checked to true to achieve the full selection
5. Set the checkbox's checked to false to achieve no selection
6. If judge, if checked is true selected state, the checked set to False, if checked false state, the checked set to true selected state.
Second, the HTML code:
<input type= "button" value= "Select All" id= "Sele"/> <input type= "button" value= "not select" I d= "SetInterval"/> <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>
Third, 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>
I hope this article will help you with your JavaScript programming.