Solve the jquery operation checkbox Select all do not select the problem

Source: Internet
Author: User

Recently, using the jquery Operation checkbox in learning, use the following method to select all, reverse:
$ ("Input[name= ' checkbox ']"). attr ("Checked", "checked");
debugging, the first two are no problem, you can display the normal check and cancel, but when the check box to select the checkbox value changed to "checked", no problem, but the check box is not displayed in the selected state, the property value changed, but does not show the check, too weird. Code changes to not get the correct display state, tangled for a long time, can not find the reason.

So various reasons, and later found an article on the internet to remind me that the original is the jquery version of the problem.
I manipulate properties with the
$ ("XXX"). attr ("Attrname"), while the version of jquery is 2.1.4, there is a compatibility and stability issue.
The jquery API clearly illustrates that 1.6+ jquery uses prop, especially the checkbox's Checked property,
Use the following code:

$ ("Input[name= ' checkbox ']"). Prop ("checked");
$ ("Input[name= ' checkbox ']"). Prop ("disabled", false);
$ ("Input[name= ' checkbox ']"). Prop ("checked", true);

So the attr changed to prop, the problem is solved.

Solve the jquery operation checkbox Select all do not select the problem

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.