Jquery1.6 adds a method prop (), which has never been used. The official explanation is only one sentence: Get the attribute value of the first element in the matched element set.
The official examples are similar to ATTR () And I don't know what the difference is. Since the new prop () method is available, it cannot be used. When should I use ATTR (), when should I use prop?
We all know that some browsers only need to write disabled and checked, while some need to write Disabled = "disabled", checked = "checked", such as ATTR ("checked ") when obtaining the checked attribute of the checkbox, you can obtain the value when it is selected. The value is "checked", but the undefined value is not selected.
JQ provides a new method "prop" to obtain these attributes to solve this problem. Previously, when we used ATTR to obtain the checked attribute, we returned "checked" and "", if you use the prop method to obtain attributes, both true and false are returned.
So when will ATTR () and prop () be used ()?
1. Add a property name. This property will take effect. Use prop ();
2. There are true and false attributes using prop ();
3. For others, use ATTR ();
Pay attention to this when upgrading jquery in the project!
We recommend that you use ATTR () and prop () as follows:
Attribute/Property |
.attr() |
.prop() |
Accesskey |
√ |
|
Align |
√ |
|
Async |
√ |
√ |
Autofocus |
√ |
√ |
Checked |
√ |
√ |
Class |
√ |
|
Contenteditable |
√ |
|
Draggable |
√ |
|
Href |
√ |
|
ID |
√ |
|
Label |
√ |
|
Location (I. e. Window. Location) |
√ |
√ |
Multiple |
√ |
√ |
Readonly |
√ |
√ |
REL |
√ |
|
Selected |
√ |
√ |
SRC |
√ |
|
Tabindex |
√ |
|
Title |
√ |
|
Type |
√ |
|
Width (if needed over.width() ) |
√ |
|