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!