The method of realizing checkbox full selection, _javascript and anti-selection by JS technique

Source: Internet
Author: User
Tags setinterval

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.

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.