On the abnormal condition of the _jquery of the total selection of input

Source: Internet
Author: User

Previous: First click on the Full selection button input display check, the second is not displayed, you need to use prop to add checked properties.

However, a problem with prop will appear, and the checked attribute will not be added (for example: $ ("input[type= ' checkbox '][name= ' che ')"). attr ("checked") gets the result to undefined), This will not be possible through the IF statement to determine whether to select, so as to achieve the reverse function.

Let's get down to the idea: since the "checked" feature is implemented by determining whether there are any properties, the checked property is cleared every time that you perform the "Select All" option, so that the checked property that you added earlier will be cleared every time. The sample code is as follows:

Select All
$ ("#quanxuan"). Click (function () {
$ ("#tb"). Find ("input[type= ' checkbox '][name= ' che ')"). Removeattr (" Checked ");
$ ("#tb"). Find ("input[type= ' checkbox '][name= ' che ']"). Prop ("checked", true);
Reverse-Select
$ ("#fanxuan"). Click (function () {
$ ("#tb"). Find ("input[type= ' checkbox '][name= ' che ')". each (function () {
if (). Is (": Checked")) {
$ (this). Removeattr ("checked");
$ (this). Prop ("checked", false);
else{
$ (this). Removeattr ("checked");
$ (this). Prop ("Checked", "checked");}});

At present, we can only think of this redundancy method, and then come up with a new solution to complement it.

The above is a small set for you to introduce the total selection of the choice of disgusting abnormal situation, very good, with reference value, I hope to help you!

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.