Recently, I want to change jquery 1.4 to version 1.7. After the replacement, the following code starts to prompt that the value is undefined.
$("#ifrTest").attr("contentWindow");
So I followed up with jquery code to check and found that the problem lies in the following code:
if ( notxml ) { name = name.toLowerCase(); hooks = jQuery.attrHooks[ name ] || ( rboolean.test( name ) ? boolHook : nodeHook ); }
In this example, the attribute name is changed to lowercase, so that the built-in attributes of the DOM object cannot get the value.
The code is located in 2298th lines,
Function ATTR: function (ELEM, name, value, pass.
I don't know if this is a bug. If you calculate a bug, submit it to the jquery project team!
My English is too bad, so I am sad! ,
Complete ATTR function code:
ATTR: function (ELEM, name, value, pass) {var ret, hooks, notxml, ntype = ELEM. nodetype; // don't get/set attributes on text, comment and attribute nodes if (! ELEM | ntype = 3 | ntype = 8 | ntype = 2) {return;} If (pass & jquery. isfunction (jquery. FN [name]) {return jquery (ELEM) [name] (value);} // fallback to prop when attributes are not supported if (typeof ELEM. getattribute = "undefined") {return jquery. prop (ELEM, name, value);} notxml = ntype! = 1 |! Jquery. isxmldoc (ELEM); // all attributes are lowercase // grab necessary hook if one is defined if (notxml) {name = Name. tolowercase (); hooks = jquery. attrhooks [name] | (rboolean. test (name )? Boolhook: nodehook);} If (value! = Undefined) {If (value = NULL) {jquery. removeattr (ELEM, name); return;} else if (hooks & "set" in hooks & notxml & (ret = hooks. set (ELEM, value, name ))! = Undefined) {return ret;} else {ELEM. setattribute (name, "" + value); Return Value ;}} else if (hooks & "get" in hooks & notxml & (ret = hooks. get (ELEM, name ))! = NULL) {return ret;} else {ret = ELEM. getattribute (name); // The method for getting the attribute here is case sensitive to the attribute name // non-existent attributes return null, we normalize to undefined return ret = NULL? Undefined: ret ;}
In addition to case sensitivity, getattribute cannot be used to obtain the contentWindow value. In version 1.4, the object is directly returned in the form of ELEM ["contentWindow,
If you need to avoid methods that cannot be set, you only need to take the DOM object directly to get the value!
Test Environment IE, FF