JS Select All not select the reverse selection

Source: Internet
Author: User

JS implementation of the full selection of non-select


1, Get Element

2, select the Select option to add click events

3, with a For loop checkbox

4, set the checkbox's checked to true to implement the Select all

5, set the checkbox's checked to false to implement the uncheck

6, if judged, 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 check state.

HTML code: <input type= "button" value= "Select All" id= "Sele"/> <input type= "button" value= "not selected" id= "SetInterval"/> & Lt;input type= "button" value= "reverse Select" id= "clear"/> <div id= "Checkboxs" > <input type= "checkbox"/><  br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox"/>&lt br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> <inpu T type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox"/&GT;&L t;br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> &LT;INP UT type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox"/>& LT;BR/></div> JS code: <script>window.onload=function () {var Sele=document.getelementbyid (' Sele ');//Get full Select var unsele=document.g Etelementbyid (' setinterval ');//Get not selected Var Clear=document.getelementbyid (' Clear ');//Get inverse var checkbox= document.getElementById (' Checkboxs ');//Get div var checked=checkbox.getelementsbytagname (' input ');//Get Div under input//           Select All Sele.onclick=function () {for (i=0;i<checked.length;i++) {checked[i].checked=true} }//not selected Unsele.onclick=function () {for (i=0;i<checked.length;i++) {Checked[i].check Ed=false}}//Anti-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>


JS Select All not select the reverse selection

Related Article

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.