jquery中怎么设置一个radio为选中状态

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery中怎么设置一个radio为选中状态相关的知识,希望对你有一定的参考价值。

参考技术A 你的$("input[name=jizai]")这个选择器会获得两个radio对象,都设置选中,只能最后一个是被选中的,因为是单选。
如果你要这么写,可以指定索引,
如:$("input[name=jizai]:eq(0)").attr("checked",'checked');
这样就是第一个选中咯。
jquery中,radio的选中与否是这么设置的。
$("#rdo1").attr("checked","checked");
$("#rdo1").removeAttr("checked");

jquery设置判断获取input单选标签选中状态

1、设置某项单选input为选中状态:
$("input[type=‘radio‘]").eq(1).attr(‘checked‘,true);
②也可设其属性checked为‘checked‘,设置完后原选中项会自动取消选中
$("input[type=‘radio‘]").eq(1).attr(‘checked‘,‘checked‘);
2、判断某单选框是否被选中状态:
? 使用object.attr(‘checked‘)==true是错的,应使用object.attr(‘checked‘)==‘checked‘作判断
$("input[type=‘radio‘]").eq(1).attr(‘checked‘)==‘checked‘;
?也可使用 is(‘:checked‘)方法作判断
$("input[type=‘radio‘]").eq(1).is(‘:checked‘);
3、获取被选中的单选框:使用 :checked 方法
$("input[type=‘radio‘]:checked");

 

以上是关于jquery中怎么设置一个radio为选中状态的主要内容,如果未能解决你的问题,请参考以下文章

如何使用Jquery获取Form表单中被选中的radio值

怎么让bootstrap的radio选中

jquery循环遍历radio单选按钮,并设置选中状态

在jQuery中,让表单当中的radio按钮默认选中第一个怎么做?

好几个radio怎么设置一个为默认选上

MFC radio button如何默认选中