Jquery's attribute module provides the following methods:
ATTR/removeattr
Prop/removeprop (1.6)
Addclass/removeclass/toggleclass/hasclass
Val
Several static methods are provided to support methods above the JQ object. For example, jquery. ATTR corresponds to ATTR, that is, the ATTR method of the JQ object internally calls jquery. ATTR. Second
Jquery. removeattr-> removeattr
Jquery. prop-> prop
ViewCodeIt can be found that jquery. Access is directly called in both the ATTR and prop methods.
ATTR: function (name, value) {return jquery. access (this, name, value, true, jquery. ATTR) ;}, prop: function (name, value) {return jquery. access (this, name, value, true, jquery. prop );},
The last parameter is jquery. ATTR and jquery. Prop. As you can imagine, this function will be called in jquery. Access. The following is the source code of jquery. Access.
Access: function (elems, key, value, exec, FN, pass) {var length = elems. length; // setting attributes attributesif (typeof key = "object") {for (var k in key) {jquery. access (elems, K, key [K], exec, FN, value);} return elems;} // setting one attributeif (value! = Undefined) {// optionally, function values get executed if exec is trueexec =! Pass & exec & jquery. isfunction (value); For (VAR I = 0; I <length; I ++) {fn (elems [I], key, exec? Value. Call (elems [I], I, FN (elems [I], key): value, pass) ;}return elems ;}// getting an attributereturn length? FN (elems [0], key): undefined ;},
When setting/retrieving attributes, traverse the jquery object and call the FN function in turn. The FN here may be jquery. ATTR and jquery. Prop.
Note that here we use for to traverse elems. This elems is actually a jquery object, which is an arraylike object.
This is probably the case. The remaining heap of hooks is used to solve the problem of browser compatibility. Such as jquery. attrhooks, jquery. prophooks, and jquery. valhooks. List as follows
1. IE6/7 does not fully support setattribute. For example, attributes such as class and for cannot be set.
2. getattribute in IE6/7 obtains the href/src attribute (relative path) value, which is different from other browsers.
3. There is a bug in obtaining the value of the button element in IE6/7.
4. IE6/7 does not support setattribute setting style/does not support getattribute obtaining style attribute values
5. The tabindex properties are different.
6. Repair of Boolean attributes, such as selected, disabled, and checked.
7. Fixed the values of select and option elements.