jquery a bug about the checkbox

Source: Internet
Author: User

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" />&nbsp;All<inputtype= "checkbox"name= "Chkgrpflag"  />&nbsp;<spanclass= "Icon-flag0"></span><inputtype= "checkbox"name= "Chkgrpflag"  />&nbsp;<spanclass= "Icon-flag1"></span><inputtype= "checkbox"name= "Chkgrpflag"  />&nbsp;<spanclass= "Icon-flag2"></span><inputtype= "checkbox"name= "Chkgrpflag"  />&nbsp;<spanclass= "Icon-flag3"></span><inputtype= "checkbox"name= "Chkgrpflag"  />&nbsp;<spanclass= "Icon-flag4"></span><inputtype= "checkbox"name= "Chkgrpflag"  />&nbsp;<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

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.