JS implementation of the full selection, not select, reverse selection

Source: Internet
Author: User

Idea: 1, get the element. 2, with a For loop calendar array, the checkbox checked set to True to achieve the full selection, the checkbox checked set to False is not selected. 3, through if judgment, if checked is true to select the state, the checked is set to False, if the checked is false, the checked is set to true selected state.

JS Code:

 1 <script> 2 window.onload=function () {3 var Checkall=document.getelementbyid (' All '); 4 var uncheck=documen T.getelementbyid (' uncheck '); 5 var Othercheck=document.getelementbyid (' Othercheck '); 6 var Div=document.getelementbyid (' div '); 7 var checkbox=div.getelementsbytagname (' input '); 8 Checkall.onclick=function () {9 for (i=0;i<checkbox.length;i++) {CHECKBOX[I].CHEC Ked=true;11};12};13 uncheck.onclick=function () {+ for (i=0;i<checkbox.length;i + +) {checkbox[i].checked=false;16};17};18 othercheck.onclick=function (                             {i=0;i<checkbox.length;i++) {$ if (checkbox[i].checked==true) {21                         Checkbox[i].checked=false;22}23 else{24 Checkbox[i].checked=true25}26 27};28};29};30 </script> 

HTML code:

 1 Select all: <input type= "button" id= "All" value= "Select All"/><br/> 2 uncheck <input type= "button" id= "uncheck" value= "not selected"/& Gt;<br/> 3 Reverse selection <input type= "button" id= "Othercheck" value= "Reverse Selection"/><br/> 4 <div id= "div" > 5 < Input type= "checkbox"/><br/> 6 <input type= "checkbox"/><br/> 7 <input type= "checkbox"     /><br/> 8 <input type= "checkbox"/><br/> 9 <input type= "checkbox"/><br/>10 <input type= "checkbox"/><br/>11 <input type= "checkbox"/><br/>12 <input type= "Chec Kbox "/><br/>13 <input type=" checkbox "/><br/>14 <input type=" checkbox "/><br/&gt ; <input type= "checkbox"/><br/>16 <input type= "checkbox"/><br/>17 <input type = "checkbox"/><br/>18 <input type= "checkbox"/><br/>19 <input type= "checkbox"/><b R/>20 <inputtype= "checkbox"/><br/>21 <input type= "checkbox"/><br/>22 <input type= "checkbox"/>& LT;BR/>23 <input type= "checkbox"/><br/>24 <input type= "checkbox"/><br/>25 </div >

JS implementation of the full selection, not select, reverse selection

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.