我的网络表单标记如下:
<input type="radio" value="0" name="fieldSelection[1]" class="optionA">
<input type="radio" value="0" name="fieldSelection[1]" class="optionB">
<input type="radio" value="0" name="fieldSelection[1]" class="optionC">
<input type="radio" value="0" name="fieldSelection[2]" class="optionA"><!--want to check this one-->
<input type="radio" value="0" name="fieldSelection[2]" class="optionB">
<input type="radio" value="0" name="fieldSelection[2]" class="optionC">
<input type="radio" value="0" name="fieldSelection[3]" class="optionA">
<input type="radio" value="0" name="fieldSelection[3]" class="optionB">
<input type="radio" value="0" name="fieldSelection[3]" class="optionC">
如何将其中一个复选框设置为选中 - 例如,选中 fieldSelection[2]
的按钮 optionA
?
这是我所拥有的,但显然它会检查所有 3 个按钮:
$('.optionA').prop('checked', true);
最佳答案
您可以使用attribute selector :
$('input.optionA[name="fieldSelection[2]"]').prop('checked', true);
Fiddle
关于jquery - 如何将某个单选按钮设置为选中 "true",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23343492/