问题
I hope you guys can help me with this one.
How can I have a radio button id="A" change it's attribute to 'checked' when radio button id="B" is selected?
Radio buttons A and B are in different groups.
Thanks!
回答1:
<input type="radio" name="group1" id="A">Radio A
<input type="radio" name="group2" id="B">Radio B
<input type="radio" name="group2" id="C">Radio C
$("input[type='radio'][name='group2']").change(function() {
if ($('#B').is(':checked')) {
$('#A').prop("checked", true);
} else {
$('#A').prop("checked", false);
}
});
Here is the jsFiddle http://jsfiddle.net/8kdb7d6o/
回答2:
$("#B").change(function(){
$("#A").prop('checked', true);
});
回答3:
to check if radio input checked or not
if($('#B').is('checked')){
$("#A").prop('checked', true);
}
来源:https://stackoverflow.com/questions/34186848/how-to-change-radio-button-to-checked-when-another-is-selected