Add fallback to prop for the window and document. Switch value to use the property instead of the attribute for back compat.
This commit is contained in:
parent
8c13cfa805
commit
4526c8b0a0
2 changed files with 55 additions and 28 deletions
|
@ -301,10 +301,15 @@ jQuery.extend({
|
|||
if ( pass && name in jQuery.attrFn ) {
|
||||
return jQuery( elem )[ name ]( value );
|
||||
}
|
||||
|
||||
|
||||
// Fallback to prop when attributes are not supported
|
||||
if ( !("getAttribute" in elem) ) {
|
||||
return jQuery.prop( elem, name, value );
|
||||
}
|
||||
|
||||
var ret, hooks,
|
||||
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
|
||||
|
||||
|
||||
// Normalize the name if needed
|
||||
name = notxml && jQuery.attrFix[ name ] || name;
|
||||
|
||||
|
@ -381,7 +386,7 @@ jQuery.extend({
|
|||
// Setting the type on a radio button after the value resets the value in IE6-9
|
||||
// Reset value to it's default in case type is set after value
|
||||
// This is for element creation
|
||||
var val = elem.getAttribute("value");
|
||||
var val = elem.value;
|
||||
elem.setAttribute( "type", value );
|
||||
if ( val ) {
|
||||
elem.value = val;
|
||||
|
@ -404,7 +409,7 @@ jQuery.extend({
|
|||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
propFix: {
|
||||
tabindex: "tabIndex",
|
||||
readonly: "readOnly",
|
||||
|
@ -422,32 +427,32 @@ jQuery.extend({
|
|||
|
||||
prop: function( elem, name, value ) {
|
||||
var nType = elem.nodeType;
|
||||
|
||||
|
||||
// don't get/set properties on text, comment and attribute nodes
|
||||
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
var ret, hooks,
|
||||
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
|
||||
|
||||
|
||||
// Try to normalize/fix the name
|
||||
name = notxml && jQuery.propFix[ name ] || name;
|
||||
|
||||
hooks = jQuery.propHooks[ name ];
|
||||
|
||||
|
||||
if ( value !== undefined ) {
|
||||
if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
|
||||
return ret;
|
||||
|
||||
|
||||
} else {
|
||||
return (elem[ name ] = value);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== undefined ) {
|
||||
return ret;
|
||||
|
||||
|
||||
} else {
|
||||
return elem[ name ];
|
||||
}
|
||||
|
@ -485,6 +490,24 @@ boolHook = {
|
|||
}
|
||||
};
|
||||
|
||||
// Use the value property for back compat
|
||||
// Use the formHook for button elements in IE6/7 (#1954)
|
||||
jQuery.attrHooks.value = {
|
||||
get: function( elem, name ) {
|
||||
if ( formHook && jQuery.nodeName( elem, "button" ) ) {
|
||||
return formHook.get( elem, name );
|
||||
}
|
||||
return elem.value;
|
||||
},
|
||||
set: function( elem, value, name ) {
|
||||
if ( formHook && jQuery.nodeName( elem, "button" ) ) {
|
||||
return formHook.set( elem, value, name );
|
||||
}
|
||||
// Does not return so that setAttribute is also used
|
||||
elem.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
// IE6/7 do not support getting/setting some attributes with get/setAttribute
|
||||
if ( !jQuery.support.getSetAttribute ) {
|
||||
|
||||
|
@ -492,7 +515,7 @@ if ( !jQuery.support.getSetAttribute ) {
|
|||
jQuery.attrFix = jQuery.propFix;
|
||||
|
||||
// Use this for any attribute on a form in IE6/7
|
||||
formHook = jQuery.attrHooks.name = jQuery.attrHooks.value = jQuery.valHooks.button = {
|
||||
formHook = jQuery.attrHooks.name = jQuery.valHooks.button = {
|
||||
get: function( elem, name ) {
|
||||
var ret;
|
||||
ret = elem.getAttributeNode( name );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue