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
34d80709
Commit
34d80709
authored
Apr 17, 2011
by
timmywil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix value attribute and val for value on button elements. Fixes #1954
parent
15da298f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
attributes.js
src/attributes.js
+3
-3
attributes.js
test/unit/attributes.js
+11
-2
No files found.
src/attributes.js
View file @
34d80709
...
...
@@ -158,7 +158,7 @@ jQuery.fn.extend({
if
(
elem
)
{
hooks
=
jQuery
.
valHooks
[
elem
.
nodeName
.
toLowerCase
()
]
||
jQuery
.
valHooks
[
elem
.
type
];
if
(
hooks
&&
"get"
in
hooks
&&
(
ret
=
hooks
.
get
(
elem
))
!==
undefined
)
{
if
(
hooks
&&
"get"
in
hooks
&&
(
ret
=
hooks
.
get
(
elem
,
"value"
))
!==
undefined
)
{
return
ret
;
}
...
...
@@ -197,7 +197,7 @@ jQuery.fn.extend({
hooks
=
jQuery
.
valHooks
[
this
.
nodeName
.
toLowerCase
()
]
||
jQuery
.
valHooks
[
this
.
type
];
// If set returns undefined, fall back to normal setting
if
(
!
hooks
||
(
"set"
in
hooks
&&
hooks
.
set
(
this
,
val
)
===
undefined
)
)
{
if
(
!
hooks
||
(
"set"
in
hooks
&&
hooks
.
set
(
this
,
val
,
"value"
)
===
undefined
)
)
{
this
.
value
=
val
;
}
});
...
...
@@ -433,7 +433,7 @@ if ( !jQuery.support.getSetAttribute ) {
// Use this for any attribute on a form in IE6/7
// And the name attribute
formHook
=
jQuery
.
attrHooks
.
name
=
{
formHook
=
jQuery
.
attrHooks
.
name
=
jQuery
.
attrHooks
.
value
=
jQuery
.
valHooks
.
button
=
{
get
:
function
(
elem
,
name
)
{
var
ret
=
elem
.
getAttributeNode
(
name
);
// Return undefined if not specified instead of empty string
...
...
test/unit/attributes.js
View file @
34d80709
...
...
@@ -77,7 +77,7 @@ test("prop(String, Object)", function() {
});
test
(
"attr(String)"
,
function
()
{
expect
(
3
2
);
expect
(
3
4
);
equals
(
jQuery
(
"#text1"
).
attr
(
"type"
),
"text"
,
"Check for type attribute"
);
equals
(
jQuery
(
"#radio1"
).
attr
(
"type"
),
"radio"
,
"Check for type attribute"
);
...
...
@@ -136,6 +136,11 @@ test("attr(String)", function() {
ok
(
!!~
jQuery
(
"#dl"
).
attr
(
"style"
).
indexOf
(
"position"
),
"Check style attribute getter, also normalize css props to lowercase"
);
ok
(
!!~
jQuery
(
"#foo"
).
attr
(
"style"
,
"position:absolute;"
).
attr
(
"style"
).
indexOf
(
"position"
),
"Check style setter"
);
// Check value on button element (#1954)
var
$button
=
jQuery
(
"<button value='foobar'>text</button>"
).
insertAfter
(
"#button"
);
equals
(
$button
.
attr
(
"value"
),
"foobar"
,
"Value retrieval on a button does not return innerHTML"
);
equals
(
$button
.
attr
(
"value"
,
"baz"
).
html
(),
"text"
,
"Setting the value does not change innerHTML"
);
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."
);
});
...
...
@@ -426,7 +431,7 @@ test("removeProp(String)", function() {
});
test
(
"val()"
,
function
()
{
expect
(
2
3
);
expect
(
2
5
);
document
.
getElementById
(
"text1"
).
value
=
"bla"
;
equals
(
jQuery
(
"#text1"
).
val
(),
"bla"
,
"Check for modified value of input element"
);
...
...
@@ -488,6 +493,10 @@ test("val()", function() {
same
(
checks
.
serialize
(),
"test=1&test=on"
,
"Get multiple checked values."
);
checks
.
remove
();
var
$button
=
jQuery
(
"<button value='foobar'>text</button>"
).
insertAfter
(
"#button"
);
equals
(
$button
.
val
(),
"foobar"
,
"Value retrieval on a button does not return innerHTML"
);
equals
(
$button
.
val
(
"baz"
).
html
(),
"text"
,
"Setting the value does not change innerHTML"
);
});
var
testVal
=
function
(
valueObj
)
{
...
...
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