Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
f2c1d2e0
Commit
f2c1d2e0
authored
Oct 17, 2011
by
timmywil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the property name in elem.removeAttribute in IE6/7 to ensure correct removals. Fixes #10514.
parent
ae6d0024
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
19 deletions
+27
-19
attributes.js
src/attributes.js
+22
-16
attributes.js
test/unit/attributes.js
+5
-3
No files found.
src/attributes.js
View file @
f2c1d2e0
...
@@ -7,6 +7,7 @@ var rclass = /[\n\t\r]/g,
...
@@ -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({
...
@@ -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({
...
@@ -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({
...
@@ -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({
...
@@ -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({
...
@@ -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({
...
@@ -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,7 +314,6 @@ jQuery.extend({
...
@@ -308,7 +314,6 @@ 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
...
@@ -355,13 +360,14 @@ jQuery.extend({
...
@@ -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
(
n
ame
);
elem
.
removeAttribute
(
getSetAttribute
?
name
:
propN
ame
);
// 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,14 +430,14 @@ jQuery.extend({
...
@@ -424,14 +430,14 @@ 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
)
{
...
@@ -510,7 +516,7 @@ boolHook = {
...
@@ -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
,
...
...
test/unit/attributes.js
View file @
f2c1d2e0
...
@@ -452,7 +452,9 @@ test("attr('tabindex', value)", function() {
...
@@ -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() {
...
@@ -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)"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment