🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/attributes/val.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,9 @@ jQuery.extend({
valHooks: {
option: {
get: function( elem ) {
var val = jQuery.find.attr( elem, "value" );
return val != null ?
val :
// Support: IE10-11+
// option.text throws exceptions (#14686, #14858)
jQuery.trim( jQuery.text( elem ) );
// Support: IE<11
// option.value not trimmed (#14858)
return jQuery.trim( elem.value );
}
},
select: {
Expand Down Expand Up @@ -130,7 +127,8 @@ jQuery.extend({

while ( i-- ) {
option = options[ i ];
if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
if ( (option.selected =
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0) ) {
optionSet = true;
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/unit/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,11 @@ test( "should not throw at $(option).val() (#14686)", 1, function() {
}
});

test( "option value not trimmed when setting via parent select", function() {
expect( 1 );
equal( jQuery( "<select><option> 2</option></select>" ).val( "2" ).val(), "2" );
});

test( "Insignificant white space returned for $(option).val() (#14858)", function() {
expect ( 3 );

Expand Down