jquery - 如何将某个单选按钮设置为选中 "true"

标签 jquery radio-button

我的网络表单标记如下:

<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/

相关文章:

jquery - 如果a有attr rel=lightbox然后addClass,问题

javascript - 在嵌套对象中搜索文本(以 Backbone.js 集合为例)

Jquery UI 选项卡 - 更改选项卡的形状

javascript - 自定义单选按钮

swift - 在 ios swift 中使用数组选择取消选择 uitableview 部分中的 radio

wpf - 更改选项卡时,RadioButton IsChecked 属性被覆盖

jquery - 从子域到主域的 $.post 调用不起作用

Javascript onchange 函数在移动设备上的选择菜单中不起作用

ruby-on-rails - simple_forms 中的 collection_radio_buttons 属性将所有内容包装在 div 中

jquery - 处理 Spring MVC 表单 :radiobutton with Jquery