Solve the jquery Operation checkbox Firefox is unable to check the problem for the second time _jquery

Source: Internet
Author: User
Recently, using the jquery operation checkbox in your work, use the following method to select all, to reverse the selection:
Copy Code code as follows:

var ischecked=allcheckobj.is (': checked ');
Ischecked?checksobj.attr (' checked ', true): checksobj.attr (' checked ', false);

Debugging in IE no problem, considering compatibility, try Firefox, encountered a problem. As a result, the following experiments were done:
The check box binds the Click event, selects once, and then clicks Uncheck, and so on. This function in IE no problem, but in Firefox test, the first two times are no problem, you can display the check and cancel, but when you go to select, check box property checkbox value to "checked", no problem, but check box does not show the selected state, Obviously the attribute value changed, but did not show tick, too strange. Code modification but not get the right display status, tangled up for a long time, can not find the reason.
Positive solution: Later by the idol direction, the original jquery version of the problem. I manipulate attributes using the
$ ("* *"). attr ("Attrname"); the jquery version uses 1.9, which is a compatibility and stability issue.
The jquery API clearly shows that 1.6+ jquery is judged by the attributes of the prop, especially the checked of the checkbox, i.e.
Copy Code code as follows:

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

In use is to change the attr to prop, the problem is solved.
Have you met this strange question? Just try it.

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.