The checkbox attribute checked = "checked" already exists, but it does not display a check.

Source: Internet
Author: User

The main cause is the jquery version.

1. ATTR ():

Obtain the attribute value of the first element in the matched element set or set one or more attributes of each matching element.

In jquery 1.6, when the attribute is not set, the. ATTR () method returns undefined. To retrieve and change Dom attributes, such as the checked, selected, or disabled status of an element, use the. Prop () method.

2. removeattr ():

Deletes an attribute from each matching element.

In IE6 versions earlier than 1.6, using jquery's removeattr method to delete disabled is invalid. The solution is to use $ ("XX"). Prop ("disabled", false );
Version 1.7 supports the deletion of disabled in IE6.

3. Prop ():

Obtain the property value of the first element in the matching element set or set one or more attributes of each matching element.

With some DOM elements or window objects with built-in properties, if you try to delete this property, the browser may produce errors. Jquery assigns the undefined value attribute for the first time, ignoring any errors generated by the browser.

4. Example:

HTML:

1 <Table class = "Table-striped table-Hover auth-table" id = "auth-table"> 2 <tbody> 3 <tr> 4 <TD> 5 <Input type = "checkbox" name = "user"> 6  7 <span> AI zuqing 1 </span> 8 </TD> 9 <TD> 10 <SPAN class = "user-email"> [email protected] </span> 11 </TD> 12 </tr> 13 <tr> 14 <TD> 15 <input type = "checkbox "Name =" user "> 16  17 <span> AI zuqing 1 </span> 18 </TD> 19 <TD> 20 <SPAN class = "user-email"> [email protected] </span> 21 </TD> 22 </tr> 23 </tbody> 24 </table>

 

JS:

 

1 // select all and invert personnel; 2 function wholechecked () {3 $ ("table # auth-table input [type = 'checkbox']"). prop ("checked", "checked"); 4} 5 function wholecheckedcancel () {6 $ ("table # auth-table input [type = 'checkbox']"). removeattr ("checked"); 7}

 

In the above JS Code, set the checked attribute of the Multi-choice box. ATTR () is used for jquery1.6 and later versions. However, in a higher version, only prop () is used () if you press ATTR to set it

When you click the Select All button for the first time, after all the checkboxes are selected, you will see that the checked attribute is changed, but the check box hooks are not displayed, because in earlier versions, if no attribute is set for the element ,. ATTR () returns undfined.

 

 

 

 

The checkbox attribute checked = "checked" already exists, but it does not display a check.

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.