Today and everyone to share a select, uncheck, uncheck the box example, this example can be used as a template, as long as the data appropriate to change the following is OK.
This is:
The code is as follows:
HTML section:
<input type= "button" value= "Select All"/id= "BTN1" > <input type= "button" value= "not selected"/id= "btn2" > <input type= " Button "value="/id= "Btn3" ><br/> <div id= "Div1" > <input type= "checkbox" ><br/> <i Nput type= "checkbox" ><br/> <input type= "checkbox" ><br/> <input type= "checkbox" ><BR/&G T <input type= "checkbox" ><br/> <input type= "checkbox" ><br/> <input type= "checkbox" >< br/> <input type= "checkbox" ><br/> <input type= "checkbox" ><br/> <input type= "Checkbo X "><br/> <input type=" checkbox "><br/> <input type=" checkbox "><br/> <input Typ e= "checkbox" ><br/> <input type= "checkbox" ><br/> <input type= "checkbox" ><br/> < Input type= "checkbox" ><br/> <input type= "checkbox" ><br/> <input type= "checkbox" ><br/ > </div>
The JS section is as follows:
Window.onload=function () {var Obtn1=document.getelementbyid (' btn1 ');//Select all var Obtn2=document.getelementbyid (' btn2 ') ;//Do not select Var Obtn3=document.getelementbyid (' Btn3 ');//Counter-select Var Odiv=document.getelementbyid (' Div1 ');//The direct parent element of all check boxes var ach= Odiv.getelementsbytagname (' input ');//Note that the acquisition element here is not using document, but rather odiv, otherwise it will choose to include the "Select, uncheck, deselect" Three check boxes, obviously illogical// Note: The main use of the checkbox inside the checked property to set, the property has two values, is true or false//Select All function Obtn1.onclick=function () {for (Var i=0;i<ach.length ; i++) {ach[i].checked=true;}};/ /Do not select function Obtn2.onclick=function () {for (Var i=0;i<ach.length;i++) {ach[i].checked=false;}};/ /anti-select function Obtn3.onclick=function () {for (Var i=0;i<ach.length;i++) {if (ach[i].checked==true) {ach[i].checked=false;} Else{ach[i].checked=true;}};};
Hope to be helpful to everyone, welcome to leave a comment together to explore Ha O (∩_∩) o~
Author: Zhi Zhi
Sign: The road long its repair far XI, I will go up and down and quest.
JS Select All, uncheck, uncheck Checkboxes (templates)