jquery check box select/Cancel Example

Source: Internet
Author: User

 jquery check box selection/Cancellation example, when you click the check box to select all the child check boxes, and then click to cancel all check boxes selected state  

Function:   A: When you click the check box, select all the child check boxes, and then click the check box to cancel all the selected states   B: There is a child check box selected, the Parent check box select all the Child check box is not selected, the parent check box does not select the code as follows:/**  * full selection function &nb sp;* @param mainid primary check box ID  * @param klass subordinate check box class  */function SelectAll (mainid,klass) { $ ("." + Klass) . each (function () {     if ($ ("#" + Mainid). attr ("checked") = = "Checked") {      $ (this). attr ("Checked", "checked");            else{      $ (this) removeattr ("checked");     &NBSP;  });     above implementation of the full selection and all the child check box, as for the implementation of the data in the controller received a check box of the array can   code as follows:/**  * check box has a Select the parent check box to select the <br> child check box does not select the parent check box does not select the ID of the  * @param father parent check box  * @param son child check box class  */function Checksoncheckbox (father,son) { $ ("." +son). Click (function () {  if ($ (this). attr ("checked") = = "Checked") {   $ (this). AddClass ("checked");  }else{   $ (this). Removeclass ("checked");  }   if ($ (".") +son). Hasclass ("checked")) {  &Nbsp;$ ("#" +father). attr ("Checked", "checked");   Console.log ("At least one child check box is selected!") ");  }else{   $ ("#" +father). Removeattr ("checked");//  Console.log ("All child check boxes are not selected!") ");  }  }; };     Above implement a child check box select the Parent check box select all child check boxes do not select the parent check box is not selected  

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.