Notes about some problems encountered when jquery makes the check box in the Project _ jquery-js tutorial

Source: Internet
Author: User
In practice, I still encountered a lot of problems. Note that in the input checkbox, it is not possible to use the ordinary attr attribute to judge. Because the checked value is checked, make a note. Check box

When I made a check box yesterday, I thought it should be quite simple at first. taking it for granted, the main function is to click a button, for example, to select this function all, then all the following lists are selected.

Later, I encountered a lot of problems in practice. Note that in the input checkbox, it is impossible to judge using the ordinary attr attribute, because the checked value is checked, this attribute can be changed only when prop is used !!!! See the api documentation. Later, Baidu found that this has been explained in the official api. The following is an example of how to attach a prop api address (": checked") in jquery to attr, prop, it is worth reading and later the code is changed;

The Code is as follows:


$ ("# Main-manage"). on ('click', "# selectAll", function (event ){
$ ("# XunTable"). find ('input'). not (": disabled"). each (function (index, el ){
If ($ ("# selectAll"). is (": checked ")){
$ (This). prop ('checked', 'true ');
}
Else {
$ (This). prop ('checked', 'false ');
$ (This). removeAttr ('checked ');
}
});
});

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.