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
a64dc040
Commit
a64dc040
authored
Nov 09, 2010
by
Colin Snover
Committed by
John Resig
Nov 09, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove conditional that prevents attr from working on non-Element nodes. Fixes #7451.
parent
d1a88b2e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
67 deletions
+66
-67
attributes.js
src/attributes.js
+63
-66
attributes.js
test/unit/attributes.js
+3
-1
No files found.
src/attributes.js
View file @
a64dc040
...
...
@@ -289,91 +289,88 @@ jQuery.extend({
// Try to normalize/fix the name
name
=
notxml
&&
jQuery
.
props
[
name
]
||
name
;
// Only do all the following if this is a node (faster for style)
if
(
elem
.
nodeType
===
1
)
{
// These attributes require special treatment
var
special
=
rspecialurl
.
test
(
name
);
// Safari mis-reports the default selected property of an option
// Accessing the parent's selectedIndex property fixes it
if
(
name
===
"selected"
&&
!
jQuery
.
support
.
optSelected
)
{
var
parent
=
elem
.
parentNode
;
if
(
parent
)
{
parent
.
selectedIndex
;
// Make sure that it also works with optgroups, see #5701
if
(
parent
.
parentNode
)
{
parent
.
parentNode
.
selectedIndex
;
}
// These attributes require special treatment
var
special
=
rspecialurl
.
test
(
name
);
// Safari mis-reports the default selected property of an option
// Accessing the parent's selectedIndex property fixes it
if
(
name
===
"selected"
&&
!
jQuery
.
support
.
optSelected
)
{
var
parent
=
elem
.
parentNode
;
if
(
parent
)
{
parent
.
selectedIndex
;
// Make sure that it also works with optgroups, see #5701
if
(
parent
.
parentNode
)
{
parent
.
parentNode
.
selectedIndex
;
}
}
}
// If applicable, access the attribute via the DOM 0 way
// 'in' checks fail in Blackberry 4.7 #6931
if
(
(
name
in
elem
||
elem
[
name
]
!==
undefined
)
&&
notxml
&&
!
special
)
{
if
(
set
)
{
// We can't allow the type property to be changed (since it causes problems in IE)
if
(
name
===
"type"
&&
rtype
.
test
(
elem
.
nodeName
)
&&
elem
.
parentNode
)
{
jQuery
.
error
(
"type property can't be changed"
);
}
if
(
value
===
null
)
{
if
(
elem
.
nodeType
===
1
)
{
elem
.
removeAttribute
(
name
);
}
}
else
{
elem
[
name
]
=
value
;
}
}
// browsers index elements by id/name on forms, give priority to attributes.
if
(
jQuery
.
nodeName
(
elem
,
"form"
)
&&
elem
.
getAttributeNode
(
name
)
)
{
return
elem
.
getAttributeNode
(
name
).
nodeValue
;
// If applicable, access the attribute via the DOM 0 way
// 'in' checks fail in Blackberry 4.7 #6931
if
(
(
name
in
elem
||
elem
[
name
]
!==
undefined
)
&&
notxml
&&
!
special
)
{
if
(
set
)
{
// We can't allow the type property to be changed (since it causes problems in IE)
if
(
name
===
"type"
&&
rtype
.
test
(
elem
.
nodeName
)
&&
elem
.
parentNode
)
{
jQuery
.
error
(
"type property can't be changed"
);
}
// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
if
(
name
===
"tabIndex"
)
{
var
attributeNode
=
elem
.
getAttributeNode
(
"tabIndex"
);
if
(
value
===
null
)
{
if
(
elem
.
nodeType
===
1
)
{
elem
.
removeAttribute
(
name
);
}
return
attributeNode
&&
attributeNode
.
specified
?
attributeNode
.
value
:
rfocusable
.
test
(
elem
.
nodeName
)
||
rclickable
.
test
(
elem
.
nodeName
)
&&
elem
.
href
?
0
:
undefined
;
}
else
{
elem
[
name
]
=
value
;
}
}
return
elem
[
name
];
// browsers index elements by id/name on forms, give priority to attributes.
if
(
jQuery
.
nodeName
(
elem
,
"form"
)
&&
elem
.
getAttributeNode
(
name
)
)
{
return
elem
.
getAttributeNode
(
name
).
nodeValue
;
}
if
(
!
jQuery
.
support
.
style
&&
notxml
&&
name
===
"style"
)
{
if
(
set
)
{
elem
.
style
.
cssText
=
""
+
value
;
}
// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
if
(
name
===
"tabIndex"
)
{
var
attributeNode
=
elem
.
getAttributeNode
(
"tabIndex"
);
return
elem
.
style
.
cssText
;
return
attributeNode
&&
attributeNode
.
specified
?
attributeNode
.
value
:
rfocusable
.
test
(
elem
.
nodeName
)
||
rclickable
.
test
(
elem
.
nodeName
)
&&
elem
.
href
?
0
:
undefined
;
}
return
elem
[
name
];
}
if
(
!
jQuery
.
support
.
style
&&
notxml
&&
name
===
"style"
)
{
if
(
set
)
{
// convert the value to a string (all browsers do this but IE) see #1070
elem
.
setAttribute
(
name
,
""
+
value
);
elem
.
style
.
cssText
=
""
+
value
;
}
// Ensure that missing attributes return undefined
// Blackberry 4.7 returns "" from getAttribute #6938
if
(
!
elem
.
attributes
[
name
]
&&
(
elem
.
hasAttribute
&&
!
elem
.
hasAttribute
(
name
))
)
{
return
undefined
;
}
return
elem
.
style
.
cssText
;
}
var
attr
=
!
jQuery
.
support
.
hrefNormalized
&&
notxml
&&
special
?
// Some attributes require a special call on IE
elem
.
getAttribute
(
name
,
2
)
:
elem
.
getAttribute
(
name
);
if
(
set
)
{
// convert the value to a string (all browsers do this but IE) see #1070
elem
.
setAttribute
(
name
,
""
+
value
);
}
// Non-existent attributes return null, we normalize to undefined
return
attr
===
null
?
undefined
:
attr
;
// Ensure that missing attributes return undefined
// Blackberry 4.7 returns "" from getAttribute #6938
if
(
!
elem
.
attributes
[
name
]
&&
(
elem
.
hasAttribute
&&
!
elem
.
hasAttribute
(
name
))
)
{
return
undefined
;
}
var
attr
=
!
jQuery
.
support
.
hrefNormalized
&&
notxml
&&
special
?
// Some attributes require a special call on IE
elem
.
getAttribute
(
name
,
2
)
:
elem
.
getAttribute
(
name
);
// Non-existent attributes return null, we normalize to undefined
return
attr
===
null
?
undefined
:
attr
;
}
});
...
...
test/unit/attributes.js
View file @
a64dc040
...
...
@@ -4,7 +4,7 @@ var bareObj = function(value) { return value; };
var
functionReturningObj
=
function
(
value
)
{
return
(
function
()
{
return
value
;
});
};
test
(
"attr(String)"
,
function
()
{
expect
(
3
0
);
expect
(
3
1
);
// This one sometimes fails randomly ?!
equals
(
jQuery
(
'#text1'
).
attr
(
'value'
),
"Test"
,
'Check for value attribute'
);
...
...
@@ -65,6 +65,8 @@ test("attr(String)", function() {
ok
(
jQuery
(
"<div/>"
).
attr
(
"doesntexist"
)
===
undefined
,
"Make sure undefined is returned when no attribute is found."
);
ok
(
jQuery
().
attr
(
"doesntexist"
)
===
undefined
,
"Make sure undefined is returned when no element is there."
);
equals
(
jQuery
(
document
).
attr
(
"nodeName"
),
"#document"
,
"attr works correctly on document nodes (bug #7451)."
);
});
if
(
!
isLocal
)
{
...
...
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