Fixed the second time that the jquery checkbox firefox could not be checked

  • 2020-03-30 01:41:39
  • OfStack

Recently, I used jquery to operate checkbox in my work. I used the following methods to select all and unselect:

There was no problem in ie when debugging. Considering compatibility, I tried firefox and encountered problems. So they did the following experiment:
The checkbox is bound to the click event, click once to select, then click to deselect, and so on. This feature in ie no problem, but in firefox tests, first two all have no problem, you can display properly selected and cancellation, but when to selected checkboxes attribute the checkbox value into "checked", no problem, but the check box, but not according to selected, attribute values changed obviously, but does not display the tick, too weird. Code modification but not the correct state of display, tangled for a long time, can not find the reason.
Correct solution: later by the idol, the original is jQuery version of the problem. I'm going to manipulate the properties with
$(" * * "). Attr (" attrName "); The jQuery version USES 1.9, which is a compatibility and stability issue.
The jQuery API clearly states that prop should be used for the 1.6+ jQuery, especially for the checked properties of the checkBox, i.e
$("input[type='checkbox']").prop("disabled", false); 
$("input[type='checkbox']").prop("checked", true); 

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

Related articles: