🌐 AI搜索 & 代理 主页
Skip to content

Commit f298cce

Browse files
committed
Made sure that the .val() logic for setting radios and checkboxes was correct. Fixes #5698.
1 parent 261b7ef commit f298cce

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ jQuery.fn.extend({
158158
}
159159

160160
if ( jQuery.isArray(val) && /radio|checkbox/.test( this.type ) ) {
161-
this.checked = jQuery.inArray(this.value || this.name, val) >= 0;
161+
this.checked = jQuery.inArray( this.value, val ) >= 0;
162162

163163
} else if ( jQuery.nodeName( this, "select" ) ) {
164164
var values = jQuery.makeArray(val);

test/unit/manipulation.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ test("clone() on XML nodes", function() {
619619
}
620620

621621
test("val()", function() {
622-
expect(11);
622+
expect(15);
623623

624624
document.getElementById('text1').value = "bla";
625625
equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
@@ -646,6 +646,22 @@ test("val()", function() {
646646
jQuery('#select3').val("");
647647
same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' );
648648

649+
var checks = jQuery("<input type='checkbox' name='test' value='1'/>").appendTo("#form")
650+
.add( jQuery("<input type='checkbox' name='test' value='2'/>").appendTo("#form") )
651+
.add( jQuery("<input type='checkbox' name='test' value=''/>").appendTo("#form") );
652+
653+
same( checks.serialize(), "", "Get unchecked values." );
654+
655+
checks.val([ "2" ]);
656+
same( checks.serialize(), "test=2", "Get a single checked value." );
657+
658+
checks.val([ "1", "" ]);
659+
same( checks.serialize(), "test=1&test=", "Get multiple checked values." );
660+
661+
checks.val([ "", "2" ]);
662+
same( checks.serialize(), "test=2&test=", "Get multiple checked values." );
663+
664+
checks.remove();
649665
});
650666

651667
var testVal = function(valueObj) {

0 commit comments

Comments
 (0)