A bug found in jquery 1.7 and later versions of $. ATTR ("attribute ")

Source: Internet
Author: User

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

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.