This article mainly introduces the solution of the selection invalidation of the checkbox in jquery, the friend who need can refer to the following
If you use jquery 1.6, the code if ($ (elem). attr ("checked")) will get a property (attribute) that does not change the check box to be selected and selected. It is used only to store the default or selected property's initial value. In order to maintain backward compatibility, the. attr () method starts with the JQuery 1.6.1+, in addition to returning the property value, the property attribute is also updated, so the Boolean attribute (Boolean property) does not need to change its value through. Prop (). It is recommended to use one of the above methods to obtain the value of checked.
Using jquery's attr method to get and set the "checked" property of the check box, found that the first full Select/deselect all valid, and then invalid, but to view the HTML source file, the check box properties have been updated, that is, the page is not updated, the correct method is as follows:
?
| 12345678910111213141516 |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script><script type="text/javascript">// <![CDATA[$(function(){$(‘.ckAll‘).click(function(){$(".box-items").each(function(){ $(this).prop("checked",!!$(".box-all").prop("checked"));});});});// ]]></script><div><label class="ckAll"><input class="box-all" type="checkbox" /><span>全选</span></label><input class="box-items" type="checkbox" /><input class="box-items" type="checkbox" /><input class="box-items" type="checkbox" /><input class="box-items" type="checkbox" /><input class="box-items" type="checkbox" /></div> |
A solution to the select-All invalidation of the checkbox in jquery