mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Fix #10773. Improve parameter handling in removeAttr.
This commit is contained in:
parent
fa96f4bdee
commit
a467aa0a77
@ -355,12 +355,12 @@ jQuery.extend({
|
|||||||
var propName, attrNames, name, l,
|
var propName, attrNames, name, l,
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
if ( elem.nodeType === 1 ) {
|
if ( value && typeof value === "string" && elem.nodeType === 1 ) {
|
||||||
attrNames = ( value || "" ).split( rspace );
|
attrNames = jQuery.trim( value ).toLowerCase().split( " " );
|
||||||
l = attrNames.length;
|
l = attrNames.length;
|
||||||
|
|
||||||
for ( ; i < l; i++ ) {
|
for ( ; i < l; i++ ) {
|
||||||
name = attrNames[ i ].toLowerCase();
|
name = attrNames[ i ];
|
||||||
propName = jQuery.propFix[ name ] || name;
|
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)
|
||||||
|
@ -481,6 +481,41 @@ test("removeAttr(String)", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("removeAttr, #", function() {
|
||||||
|
|
||||||
|
var div = jQuery("<div />");
|
||||||
|
|
||||||
|
ok( div.removeAttr( "" ), "empty string" );
|
||||||
|
ok( div.removeAttr(), "nothing" );
|
||||||
|
ok( div.removeAttr( false ), "false" );
|
||||||
|
ok( div.removeAttr( true ), "true" );
|
||||||
|
ok( div.removeAttr({ }), "object" );
|
||||||
|
ok( div.removeAttr( function(){} ), "function" );
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test("removeAttr(Multi String)", function() {
|
||||||
|
expect(8);
|
||||||
|
|
||||||
|
var div = jQuery("<div id='a' alt='b' title='c' rel='d'></div>"),
|
||||||
|
tests = {
|
||||||
|
id: "a",
|
||||||
|
alt: "b",
|
||||||
|
title: "c",
|
||||||
|
rel: "d"
|
||||||
|
};
|
||||||
|
|
||||||
|
jQuery.each( tests, function( key, val ) {
|
||||||
|
equal( div.attr(key), val, "Attribute `" + key + "` exists, and has a value of `" + val + "`" );
|
||||||
|
});
|
||||||
|
|
||||||
|
div.removeAttr( "id alt title rel " );
|
||||||
|
|
||||||
|
jQuery.each( tests, function( key, val ) {
|
||||||
|
equal( div.attr(key), undefined, "Attribute `" + key + "` was removed" );
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("prop(String, Object)", function() {
|
test("prop(String, Object)", function() {
|
||||||
expect(31);
|
expect(31);
|
||||||
|
|
||||||
@ -548,28 +583,6 @@ test("prop(String, Object)", function() {
|
|||||||
equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
|
equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
|
||||||
});
|
});
|
||||||
|
|
||||||
test("removeAttr(Multi String)", function() {
|
|
||||||
expect(8);
|
|
||||||
|
|
||||||
var div = jQuery("<div id='a' alt='b' title='c' rel='d'></div>"),
|
|
||||||
tests = {
|
|
||||||
id: "a",
|
|
||||||
alt: "b",
|
|
||||||
title: "c",
|
|
||||||
rel: "d"
|
|
||||||
};
|
|
||||||
|
|
||||||
jQuery.each( tests, function( key, val ) {
|
|
||||||
equal( div.attr(key), val, "Attribute `" + key + "` exists, and has a value of `" + val + "`" );
|
|
||||||
});
|
|
||||||
|
|
||||||
div.removeAttr( "id alt title rel" );
|
|
||||||
|
|
||||||
jQuery.each( tests, function( key, val ) {
|
|
||||||
equal( div.attr(key), undefined, "Attribute `" + key + "` was removed" );
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prop('tabindex')", function() {
|
test("prop('tabindex')", function() {
|
||||||
expect(8);
|
expect(8);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user