A solution to the full selection failure of checkbox in jquery _jquery

Source: Internet
Author: User

If you use jquery 1.6, code if (elem). attr ("Checked"), you will get an attribute that does not change the check box is selected and selected. It is simply used to store the initial value of the default or selected property. To maintain backward compatibility, the. attr () method starts with the JQuery 1.6.1+ and, in addition to returning property values, the property properties are updated, so the Boolean attribute (Boolean property) does not need to pass. Prop () to change its value. It is recommended to use one of the above methods to obtain the checked value.

Using the attr method of jquery to get and set the "checked" property of the check box, it is found that the first full selection/cancellation is valid, and then it is invalid, but viewing the HTML source file, the checkbox properties have been updated, and the correct way to do this is not to update the page:

 <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> Select </span></label> <input class= "Box-items" type= "checkbox"/> <input "class=" type= "checkbox"/> <input class= "box-items" type= "checkbox"/> <input "class=" box-items "checkbox"/ > <input class= "box-items" type= "checkbox"/> </div> 

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.