Now make a Web page to achieve a very simple function: Give a "Select all" check box and several controlled check boxes, click on the "Select All" check box to select All or completely cancel the other several check boxes. Just such a simple function, but let me toss for a long time, eventually found to be a jquery bug. Say less nonsense, directly on the code.
<inputID= "Chkall"type= "checkbox" /> All<inputtype= "checkbox"name= "Chkgrpflag" /> <spanclass= "Icon-flag0"></span><inputtype= "checkbox"name= "Chkgrpflag" /> <spanclass= "Icon-flag1"></span><inputtype= "checkbox"name= "Chkgrpflag" /> <spanclass= "Icon-flag2"></span><inputtype= "checkbox"name= "Chkgrpflag" /> <spanclass= "Icon-flag3"></span><inputtype= "checkbox"name= "Chkgrpflag" /> <spanclass= "Icon-flag4"></span><inputtype= "checkbox"name= "Chkgrpflag" /> <spanclass= "Icon-flag5"></span>
Display effect:
JS Code:
$ ("#chkAll"). Click (function () { $ (' input[name= ' Chkgrpflag "] '). attr (" Checked ", this.checked); });
The jquery version used is 1.11.2, the results of the first click on the "All" check box, the selection of the other check box, the second click on the "All" check box, the full cancellation of the other check box, from the third time has been invalid. Tested for both IE and chrome.
Later, with the 1.7.2 version of jquery, the problem disappears. Because the project is inconvenient to replace the jquery version, but instead of using DOM operation.
There seems to be some flaws in the high-version of jquery.
jquery a bug about the checkbox