Solve the problem that all checkbox selections in the jquery operation cannot be selected.

Source: Internet
Author: User

Solve the problem that all checkbox selections in the jquery operation cannot be selected.
Solve the problem that all checkbox selections in the jquery operation cannot be selected.

Recently, I used jquery to operate checkbox in my work. I used the following method to select all and invert:
$ (Input [name = 'checkbox']). attr (checked, checked );
During debugging, the previous two times are normal and can be properly displayed and canceled. However, when you select the check box again, the attribute checkbox value of the check box is changed to checked, however, the check box does not display the selected status. It is strange that the attribute value is changed but the check box is not displayed. The code is modified but cannot be correctly displayed. After a long time, you cannot find the cause.

I found an article on the Internet to remind me that it was a jQuery version issue.
My operation properties use
$ (XXX). attr (attrName); While jQuery uses 2.1.1, there is a compatibility and stability problem.
JQuery API clearly states that more than 1.6 of jQuery should use prop, especially the checked attribute judgment of checkBox, that is
The Code is as follows:

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

Therefore, change attr to prop to solve the problem.
If you encounter this strange problem, please try it!

 

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.