Select all, uncheck and reverse the Multi box

Source: Internet
Author: User

To implement the selection-related mappings for a multi-box, implement the following logic:

1, the selection box is clicked, so the sub-box is selected.

2, when the whole selection state, the sub-box of one of the undo click, All box automatic unchecked

3, for the full selection of the state, the sub-box selection of all, the last sub-selection box after the click, the entire marquee automatically checked

var information=$ ("#" +flag). Find (". Information"); var  $newsCheck  = information.find (" Input[name= ' Newscheck ');//Multi box Select all with no $ (". All"). Click (function () {         if (this.checked) {            $ (this). Parents (). Parents (). Siblings (". Lists"). Find ("Input[name= ' Newscheck ']"). each (function () {this.checked=true;});         }else{             $ (This). Parents (). Parents (). Siblings (". Lists"). Find ("Input[name= ' Newscheck ']"). each (function () {this.checked=false;});         }    });//Sub-marquee Select $ ("Input[name= ' NewsCheck ')" ). Click (function ()  {    var temp=document.getelementsbyclassname ("All");     for (var i=0;i<temp.length;i++) {       if (Temp[i]. Id == flag+ "All") {           temp[i].checked= ($ Newscheck.length ==information.find ("Input[name= ' Newscheck ']:checked"). length ? true :  false);        }    });
<div id= "Informcontent" >    <div class= "InformTitle title-blue" > News </div>    <div class= "Information" >         <div class= "Informmenu" >             <div class= "Allcheck" ><input type= "checkbox"   class= "All"   Id= "Informcontentall" ><span> full selection </span></div>             <div class= "Threebutton" ></div >            <div class= "AddButton"  id= "NEWSPB" ></div>         </div>        <div class= "Lists" >          <div class= "Informlist" >                 <div class= "Newstitle" ><input type= " CheckBox " name=" Newscheck ">&nbsp;&nbsp; Facebook prise open Apple homekit  push IoT cloud Platform <span  class= "Newstime" >2015-2-10</span></div>                 <div class= "Newstitle" ><input type= " CheckBox " name=" Newscheck ">&nbsp;&nbsp; Facebook prise open Apple homekit  push IoT cloud Platform <span  class= "Newstime" >2015-2-10</span></div>         <div class= "Newstitle" >< input type= "checkbox"  name= "Newscheck" >&nbsp;&nbsp; Facebook prise open Apple homekit  push IoT cloud Platform <span  class= "Newstime" >2015-2-10</span></div>                     </div>     </div></div><div id= "Activitycontent" >    <div class= " Informtitle title-red "> Activity </div>    <div class=" Information ">         <div class= "Informmenu" >             <div class= "Allcheck" ><input type= "checkbox "  class=" All " id=" Activitycontentall "><span> Select all </span></div>             <div class= "Threebutton" ></div>             <div class= "AddButton"   id= "ActivityPB" ></div>        </div >        <div class= "Lists" >             <div class= "Informlist" >                      <div  class= "Newstitle" ><input type= "checkbox"  name= "Newscheck" >&nbsp;&nbsp; Facebook prise open Apple homekit  push IoT cloud Platform <span  class= "Newstime" >2015-2-10</span></div>                      <div class= "Newstitle" ><input type= "checkbox"  name= "Newscheck" >&nbsp;&nbsp; Facebook prise open Apple homekit  push IoT cloud Platform <span  class= "Newstime" >2015-2-10</span></div>                      <div class= "NewsTitle" ><input type= "checkbox"  name= "Newscheck" >&nbsp;&nbsp; Facebook prise open Apple homekit  push IoT cloud Platform <span  class= "Newstime" >2015-2-10</span></div>                  </div>         </div>    </div></div> 

Here I'm going to explain that I've covered two sets of boxes in one page, and the related class names of the two sets of checkboxes are all named the same, so I want to make a generic check style.

$ (". All") represents a Select checkbox for both sets of checkboxes, and the two groups of sub-marquee name are newscheck. The variable flag information is a variable used to differentiate between two sets of multi-marquee boxes. Flag has two values: "Informcontent" and "activitycontent", as to how the specific value is converted depends on each individual's project.


Select all, uncheck and reverse the Multi box

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.