"JS" Select All, uncheck, uncheck box (template)

Source: Internet
Author: User

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" &GT;&LT;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/> &lt 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.