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
a27b5d04
Commit
a27b5d04
authored
Jul 23, 2008
by
Ariel Flesler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jquery core: closes #2652. val() supports option elements, also simplified the code.
parent
69212c50
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
5 deletions
+21
-5
core.js
src/core.js
+4
-1
index.html
test/index.html
+1
-0
core.js
test/unit/core.js
+14
-2
selector.js
test/unit/selector.js
+2
-2
No files found.
src/core.js
View file @
a27b5d04
...
@@ -362,6 +362,9 @@ jQuery.fn = jQuery.prototype = {
...
@@ -362,6 +362,9 @@ jQuery.fn = jQuery.prototype = {
if
(
this
.
length
)
{
if
(
this
.
length
)
{
var
elem
=
this
[
0
];
var
elem
=
this
[
0
];
if
(
jQuery
.
nodeName
(
elem
,
'option'
)
)
return
(
elem
.
attributes
.
value
||
{}).
specified
?
elem
.
value
:
elem
.
text
;
// We need to handle select boxes special
// We need to handle select boxes special
if
(
jQuery
.
nodeName
(
elem
,
"select"
)
)
{
if
(
jQuery
.
nodeName
(
elem
,
"select"
)
)
{
var
index
=
elem
.
selectedIndex
,
var
index
=
elem
.
selectedIndex
,
...
@@ -379,7 +382,7 @@ jQuery.fn = jQuery.prototype = {
...
@@ -379,7 +382,7 @@ jQuery.fn = jQuery.prototype = {
if
(
option
.
selected
)
{
if
(
option
.
selected
)
{
// Get the specifc value for the option
// Get the specifc value for the option
value
=
jQuery
.
browser
.
msie
&&
!
option
.
attributes
.
value
.
specified
?
option
.
text
:
option
.
value
;
value
=
jQuery
(
option
).
val
()
;
// We don't need an array for one selects
// We don't need an array for one selects
if
(
one
)
if
(
one
)
...
...
test/index.html
View file @
a27b5d04
...
@@ -86,6 +86,7 @@
...
@@ -86,6 +86,7 @@
<option
id=
"option3b"
selected=
"selected"
value=
"1"
>
1
</option>
<option
id=
"option3b"
selected=
"selected"
value=
"1"
>
1
</option>
<option
id=
"option3c"
selected=
"selected"
value=
"2"
>
2
</option>
<option
id=
"option3c"
selected=
"selected"
value=
"2"
>
2
</option>
<option
id=
"option3d"
value=
"3"
>
3
</option>
<option
id=
"option3d"
value=
"3"
>
3
</option>
<option
id=
"option3e"
>
no value
</option>
</select>
</select>
<object
id=
"object1"
codebase=
"stupid"
>
<object
id=
"object1"
codebase=
"stupid"
>
...
...
test/unit/core.js
View file @
a27b5d04
...
@@ -1142,11 +1142,23 @@ test("jQuery.extend(Object, Object)", function() {
...
@@ -1142,11 +1142,23 @@ test("jQuery.extend(Object, Object)", function() {
});
});
test
(
"val()"
,
function
()
{
test
(
"val()"
,
function
()
{
expect
(
3
);
expect
(
8
);
equals
(
jQuery
(
"#text1"
).
val
(),
"Test"
,
"Check for value of input element"
);
equals
(
jQuery
(
"#text1"
).
val
(),
"Test"
,
"Check for value of input element"
);
// ticket #1714 this caused a JS error in IE
// ticket #1714 this caused a JS error in IE
equals
(
jQuery
(
"#first"
).
val
(),
""
,
"Check a paragraph element to see if it has a value"
);
equals
(
jQuery
(
"#first"
).
val
(),
""
,
"Check a paragraph element to see if it has a value"
);
ok
(
jQuery
([]).
val
()
===
undefined
,
"Check an empty jQuery object will return undefined from val"
);
ok
(
jQuery
([]).
val
()
===
undefined
,
"Check an empty jQuery object will return undefined from val"
);
equals
(
jQuery
(
'#select2'
).
val
(),
'3'
,
'Call val() on a single="single" select'
);
isSet
(
jQuery
(
'#select3'
).
val
(),
[
'1'
,
'2'
],
'Call val() on a multiple="multiple" select'
);
equals
(
jQuery
(
'#option3c'
).
val
(),
'2'
,
'Call val() on a option element with value'
);
equals
(
jQuery
(
'#option3a'
).
val
(),
''
,
'Call val() on a option element with empty value'
);
equals
(
jQuery
(
'#option3e'
).
val
(),
'no value'
,
'Call val() on a option element with no value attribute'
);
});
});
test
(
"val(String/Number)"
,
function
()
{
test
(
"val(String/Number)"
,
function
()
{
...
@@ -1235,7 +1247,7 @@ test("not()", function() {
...
@@ -1235,7 +1247,7 @@ test("not()", function() {
isSet
(
jQuery
(
"p"
).
not
(
"#ap, #sndp, .result"
).
get
(),
q
(
"firstp"
,
"en"
,
"sap"
,
"first"
),
"not('selector, selector')"
);
isSet
(
jQuery
(
"p"
).
not
(
"#ap, #sndp, .result"
).
get
(),
q
(
"firstp"
,
"en"
,
"sap"
,
"first"
),
"not('selector, selector')"
);
isSet
(
jQuery
(
"p"
).
not
(
jQuery
(
"#ap, #sndp, .result"
)).
get
(),
q
(
"firstp"
,
"en"
,
"sap"
,
"first"
),
"not(jQuery)"
);
isSet
(
jQuery
(
"p"
).
not
(
jQuery
(
"#ap, #sndp, .result"
)).
get
(),
q
(
"firstp"
,
"en"
,
"sap"
,
"first"
),
"not(jQuery)"
);
equals
(
jQuery
(
"p"
).
not
(
document
.
getElementsByTagName
(
"p"
)).
length
,
0
,
"not(Array-like DOM collection)"
);
equals
(
jQuery
(
"p"
).
not
(
document
.
getElementsByTagName
(
"p"
)).
length
,
0
,
"not(Array-like DOM collection)"
);
isSet
(
jQuery
(
"#form option"
).
not
(
"option.emptyopt:contains('Nothing'),[selected],[value='1']"
).
get
(),
q
(
"option1c"
,
"option1d"
,
"option2c"
,
"option3d"
),
"not('complex selector')"
);
isSet
(
jQuery
(
"#form option"
).
not
(
"option.emptyopt:contains('Nothing'),[selected],[value='1']"
).
get
(),
q
(
"option1c"
,
"option1d"
,
"option2c"
,
"option3d"
,
"option3e"
),
"not('complex selector')"
);
var
selects
=
jQuery
(
"#form select"
);
var
selects
=
jQuery
(
"#form select"
);
isSet
(
selects
.
not
(
selects
[
1
]
),
q
(
"select1"
,
"select3"
),
"filter out DOM element"
);
isSet
(
selects
.
not
(
selects
[
1
]
),
q
(
"select1"
,
"select3"
),
"filter out DOM element"
);
...
...
test/unit/selector.js
View file @
a27b5d04
...
@@ -195,8 +195,8 @@ test("pseudo (:) selectors", function() {
...
@@ -195,8 +195,8 @@ test("pseudo (:) selectors", function() {
t
(
"Text Contains"
,
"a:contains('Google Groups')"
,
[
"groups"
]
);
t
(
"Text Contains"
,
"a:contains('Google Groups')"
,
[
"groups"
]
);
t
(
"Element Preceded By"
,
"p ~ div"
,
[
"foo"
,
"fx-queue"
,
"fx-tests"
,
"moretests"
]
);
t
(
"Element Preceded By"
,
"p ~ div"
,
[
"foo"
,
"fx-queue"
,
"fx-tests"
,
"moretests"
]
);
t
(
"Not"
,
"a.blog:not(.link)"
,
[
"mark"
]
);
t
(
"Not"
,
"a.blog:not(.link)"
,
[
"mark"
]
);
t
(
"Not - multiple"
,
"#form option:not(:contains('Nothing'),#option1b,:selected)"
,
[
"option1c"
,
"option1d"
,
"option2b"
,
"option2c"
,
"option3d"
]
);
t
(
"Not - multiple"
,
"#form option:not(:contains('Nothing'),#option1b,:selected)"
,
[
"option1c"
,
"option1d"
,
"option2b"
,
"option2c"
,
"option3d"
,
"option3e"
]
);
t
(
"Not - complex"
,
"#form option:not([id^='opt']:gt(0):nth-child(-n+3))"
,
[
"option1a"
,
"option1d"
,
"option2d"
,
"option3d"
]
);
t
(
"Not - complex"
,
"#form option:not([id^='opt']:gt(0):nth-child(-n+3))"
,
[
"option1a"
,
"option1d"
,
"option2d"
,
"option3d"
,
"option3e"
]
);
t
(
"Not - recursive"
,
"#form option:not(:not(:selected))[id^='option3']"
,
[
"option3b"
,
"option3c"
]
);
t
(
"Not - recursive"
,
"#form option:not(:not(:selected))[id^='option3']"
,
[
"option3b"
,
"option3c"
]
);
t
(
"nth Element"
,
"p:nth(1)"
,
[
"ap"
]
);
t
(
"nth Element"
,
"p:nth(1)"
,
[
"ap"
]
);
...
...
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