mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Use the property name in elem.removeAttribute in IE6/7 to ensure correct removals. Fixes #10514.
This commit is contained in:
parent
ae6d0024c8
commit
f2c1d2e016
@ -7,6 +7,7 @@ var rclass = /[\n\t\r]/g,
|
|||||||
rfocusable = /^(?:button|input|object|select|textarea)$/i,
|
rfocusable = /^(?:button|input|object|select|textarea)$/i,
|
||||||
rclickable = /^a(?:rea)?$/i,
|
rclickable = /^a(?:rea)?$/i,
|
||||||
rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
|
rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
|
||||||
|
getSetAttribute = jQuery.support.getSetAttribute,
|
||||||
nodeHook, boolHook, fixSpecified;
|
nodeHook, boolHook, fixSpecified;
|
||||||
|
|
||||||
jQuery.fn.extend({
|
jQuery.fn.extend({
|
||||||
@ -143,8 +144,10 @@ jQuery.fn.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
hasClass: function( selector ) {
|
hasClass: function( selector ) {
|
||||||
var className = " " + selector + " ";
|
var className = " " + selector + " ",
|
||||||
for ( var i = 0, l = this.length; i < l; i++ ) {
|
i = 0,
|
||||||
|
l = this.length;
|
||||||
|
for ( ; i < l; i++ ) {
|
||||||
if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
|
if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -154,7 +157,7 @@ jQuery.fn.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
val: function( value ) {
|
val: function( value ) {
|
||||||
var hooks, ret,
|
var hooks, ret, isFunction,
|
||||||
elem = this[0];
|
elem = this[0];
|
||||||
|
|
||||||
if ( !arguments.length ) {
|
if ( !arguments.length ) {
|
||||||
@ -177,7 +180,7 @@ jQuery.fn.extend({
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isFunction = jQuery.isFunction( value );
|
isFunction = jQuery.isFunction( value );
|
||||||
|
|
||||||
return this.each(function( i ) {
|
return this.each(function( i ) {
|
||||||
var self = jQuery(this), val;
|
var self = jQuery(this), val;
|
||||||
@ -225,7 +228,7 @@ jQuery.extend({
|
|||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
get: function( elem ) {
|
get: function( elem ) {
|
||||||
var value,
|
var value, i, max, option,
|
||||||
index = elem.selectedIndex,
|
index = elem.selectedIndex,
|
||||||
values = [],
|
values = [],
|
||||||
options = elem.options,
|
options = elem.options,
|
||||||
@ -237,8 +240,10 @@ jQuery.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Loop through all the selected options
|
// Loop through all the selected options
|
||||||
for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
|
i = one ? index : 0;
|
||||||
var option = options[ i ];
|
max = one ? index + 1 : options.length;
|
||||||
|
for ( ; i < max; i++ ) {
|
||||||
|
option = options[ i ];
|
||||||
|
|
||||||
// Don't return options that are disabled or in a disabled optgroup
|
// Don't return options that are disabled or in a disabled optgroup
|
||||||
if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) &&
|
if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) &&
|
||||||
@ -292,7 +297,8 @@ jQuery.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
attr: function( elem, name, value, pass ) {
|
attr: function( elem, name, value, pass ) {
|
||||||
var nType = elem.nodeType;
|
var ret, hooks, notxml,
|
||||||
|
nType = elem.nodeType;
|
||||||
|
|
||||||
// don't get/set attributes on text, comment and attribute nodes
|
// don't get/set attributes on text, comment and attribute nodes
|
||||||
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
|
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
|
||||||
@ -308,8 +314,7 @@ jQuery.extend({
|
|||||||
return jQuery.prop( elem, name, value );
|
return jQuery.prop( elem, name, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret, hooks,
|
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
|
||||||
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
|
|
||||||
|
|
||||||
// Normalize the name if needed
|
// Normalize the name if needed
|
||||||
if ( notxml ) {
|
if ( notxml ) {
|
||||||
@ -355,13 +360,14 @@ jQuery.extend({
|
|||||||
|
|
||||||
for ( ; i < l; i++ ) {
|
for ( ; i < l; i++ ) {
|
||||||
name = attrNames[ i ].toLowerCase();
|
name = attrNames[ i ].toLowerCase();
|
||||||
|
propName = jQuery.propFix[ name ] || name;
|
||||||
|
|
||||||
// See #9699 for explanation of this approach (setting first, then removal)
|
// See #9699 for explanation of this approach (setting first, then removal)
|
||||||
jQuery.attr( elem, name, "" );
|
jQuery.attr( elem, name, "" );
|
||||||
elem.removeAttribute( name );
|
elem.removeAttribute( getSetAttribute ? name : propName );
|
||||||
|
|
||||||
// Set corresponding property to false for boolean attributes
|
// Set corresponding property to false for boolean attributes
|
||||||
if ( rboolean.test( name ) && (propName = jQuery.propFix[ name ] || name) in elem ) {
|
if ( rboolean.test( name ) && propName in elem ) {
|
||||||
elem[ propName ] = false;
|
elem[ propName ] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -424,15 +430,15 @@ jQuery.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
prop: function( elem, name, value ) {
|
prop: function( elem, name, value ) {
|
||||||
var nType = elem.nodeType;
|
var ret, hooks, notxml,
|
||||||
|
nType = elem.nodeType;
|
||||||
|
|
||||||
// don't get/set properties on text, comment and attribute nodes
|
// don't get/set properties on text, comment and attribute nodes
|
||||||
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
|
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret, hooks,
|
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
|
||||||
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
|
|
||||||
|
|
||||||
if ( notxml ) {
|
if ( notxml ) {
|
||||||
// Fix name and attach hooks
|
// Fix name and attach hooks
|
||||||
@ -510,7 +516,7 @@ boolHook = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// IE6/7 do not support getting/setting some attributes with get/setAttribute
|
// IE6/7 do not support getting/setting some attributes with get/setAttribute
|
||||||
if ( !jQuery.support.getSetAttribute ) {
|
if ( !getSetAttribute ) {
|
||||||
|
|
||||||
fixSpecified = {
|
fixSpecified = {
|
||||||
name: true,
|
name: true,
|
||||||
|
@ -452,7 +452,9 @@ test("attr('tabindex', value)", function() {
|
|||||||
|
|
||||||
test("removeAttr(String)", function() {
|
test("removeAttr(String)", function() {
|
||||||
expect(9);
|
expect(9);
|
||||||
equal( jQuery("#mark").removeAttr( "class" )[0].className, "", "remove class" );
|
var $first;
|
||||||
|
|
||||||
|
equal( jQuery("#mark").removeAttr( "class" ).attr("class"), undefined, "remove class" );
|
||||||
equal( jQuery("#form").removeAttr("id").attr("id"), undefined, "Remove id" );
|
equal( jQuery("#form").removeAttr("id").attr("id"), undefined, "Remove id" );
|
||||||
equal( jQuery("#foo").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute" );
|
equal( jQuery("#foo").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute" );
|
||||||
equal( jQuery("#form").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute on a form" );
|
equal( jQuery("#form").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute on a form" );
|
||||||
@ -465,8 +467,8 @@ test("removeAttr(String)", function() {
|
|||||||
equal( document.getElementById("text1").readOnly, false, "removeAttr sets boolean properties to false" );
|
equal( document.getElementById("text1").readOnly, false, "removeAttr sets boolean properties to false" );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jQuery("#first").attr("contenteditable", "true").removeAttr("contenteditable");
|
$first = jQuery("#first").attr("contenteditable", "true").removeAttr("contenteditable");
|
||||||
ok( true, "Removing contenteditable does not throw an error.");
|
equal( $first.attr('contenteditable'), undefined, "Remove the contenteditable attribute" );
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
ok( false, "Removing contenteditable threw an error (#10429)" );
|
ok( false, "Removing contenteditable threw an error (#10429)" );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user