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