Solve the problem that the checkbox Firefox cannot be checked for the second time in the jquery operation. _ jquery

Source: Internet
Author: User
In the work, use jquery to operate checkbox for full selection and invert selection. The problem is that Firefox cannot check the problem for the second time. A detailed answer is provided below, if you are interested, refer to using jquery to operate the checkbox at work recently. Use the following methods to select all and invert:

The Code is as follows:


Var ischecked = allCheckObj. is (': checked ');
Ischecked? ChecksObj. attr ('checked', true): checksObj. attr ('checked', false );


There was no problem with ie during debugging. Considering compatibility, I tried firefox and encountered a problem. Therefore, we did the following experiments:
The check box is bound with a click event. click Select once, click unselect, and so on. This function is okay in ie, but it is okay in the previous two tests in firefox. It can be properly displayed and canceled, but when it is selected again, the checkbox value of the attribute of the check box is changed to "checked". No problem, but the check box does not display the selected status. It is strange that the attribute value is changed but not checked. The code is modified but cannot be correctly displayed. After a long time, you cannot find the cause.
Positive solution: it turned out to be a jQuery version after idol guidance. My operation properties use
$ ("**"). Attr ("attrName"); jQuery uses 1.9, which is a problem of compatibility and stability.
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 [type = 'checkbox']"). prop ("checked ");
$ ("Input [type = 'checkbox']"). prop ("disabled", false );
$ ("Input [type = 'checkbox']"). prop ("checked", true );


In use, change attr to prop to solve the problem.
Have you encountered this strange problem? 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.