check box checkbox Check Event

Source: Internet
Author: User

The jquery-1.11 used in the project today needs to detect the selected state of a checkbox and take it for granted. attr ("Checked"), the result is that the value is undefined undefined regardless of whether it is selected or not.

Tossing for a half day, found:As of JQuery 1.6, the. attr () method returns undefined for attributes that has not been set. In Addition, .attr ()  should not being used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use The .prop () method.

  pay attention to the last two words, say what. attr () can not be used for ordinary objects, arrays, windows, documents what things, to regain the change DOM properties, with the. Prop () method.

  In addition: checked property is initialized when the page is initialized and does not change as the state changes. So if the checkbox is initially selected, the return is checked, and if it is not selected at first, then the undefined is returned.

  Result: Prop () available

  check box Select all/Reverse

traverse checkbox to determine if there is a check

check box checkbox to select an event

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.