All records of Jquery selection and invert selection problems. All records of jquery Selection

Source: Internet
Author: User

All records of Jquery selection and invert selection problems. All records of jquery Selection

<Div id = "list"> <ul id = "choseList"> <li> <input type = "checkbox" name = "chose" value = "1"> playing basketball </ li> <input type = "checkbox" name = "chose" value = "1"> soccer </li> <input type = "checkbox" name = "chose" value = "1"> playing table tennis </li> <input type = "checkbox" name = "chose" value = "1"> swimming </ li> <input type = "checkbox" name = "chose" value = "1"> badminton </li> <input type = "checkbox" name = "chose" value = "1"> volleyball </li> </ul> </div> <input type = "button" id = "all" value = "select all /do not select all "> <input type =" button "value =" select all "class =" btn "id =" selectAll "> <input type =" button "value =" do not select all "class =" btn "id =" unSelect ">

 


Jquery code is implemented in this way :( refer to a great god EdieLei reply blog link http://www.cnblogs.com/edielei)

I personally think this method is better than each, so I will record it:

Var a = true; $ (function () {// select all/do not select all $ ('# all'). click (function () {ck (a); a =? False: true;}); // select all $ ('# selectAll '). click (function () {ck (true) ;}); // do not select $ ('# unselect '). click (function () {ck (false) ;}); function ck (B) {$ ('input [name = "chose"] '). prop ('checked', B );}

Of course, the each method can also be:

$("#list :checkbox").each(function () {                if ($(this).attr("checked") == true) {                       $(this).attr("checked",false) ;                }                else {                                   $(this).attr("checked",true);                  }                             }); 

/// Refer to Langya manba's blog

 

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.