jquery-1.10.2 gets the Checked property of a checkbox is always undefined

Source: Internet
Author: User

The jquery-1.10.2 used in the project need 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.

To find information, we hereby record:

JQ Official Website Description:

As of the jQuery 1.6, the. attr () method returns undefined for attributes that has not been set. In addition,. attr () should am used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the. Prop () method.

. attr () cannot be used for normal objects, arrays, windows, documents, etc., to regain the change DOM properties, using the. Prop () method.

Using the. Prop method is really feasible.

Post a code like this:

function Changeallindustryselectstate () {            var checked = $ ("#allIndustryCkbx"). Prop ("checked");            if (checked) {//Select All trades                $ ("table Input[type=checkbox]"). Prop ("checked", true);            } else {//Cancel all trades Select                $ (" Table Input[type=checkbox]). Prop ("checked", false);}        }

  

jquery-1.10.2 gets the Checked property of a checkbox is always undefined

Related Article

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.