A solution to the select-All invalidation of the checkbox in jquery

Source: Internet
Author: User

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

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.