栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

JQuery控制radio选中和不选中方法总结

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JQuery控制radio选中和不选中方法总结

一、设置选中方法
复制代码 代码如下:
$("input[name='名字']").get(0).checked=true;
$("input[name='名字']").attr('checked','true');
$("input[name='名字']:eq(0)").attr("checked",'checked');
$("input[name='radio_name'][checked]").val();  //获取被选中Radio的Value值

二、设置选中和不选中示例
复制代码 代码如下:


#jquery中,radio的选中与否是这么设置的。
$("#rdo1").attr("checked","checked");
$("#rdo1").removeAttr("checked");

通过name
复制代码 代码如下:
$("input:radio[name="analyfsftype"]").eq(0).attr("checked",'checked');
$("input:radio[name="analyshowtype"]").attr("checked",false);

通过id
复制代码 代码如下:
$("#tradeType0").attr("checked","checked");
$("#tradeType1").attr("checked",false);

三、另一种设置选中方法

复制代码 代码如下:
 

您的性别: 
复制代码 代码如下:
checked/>男 
checked/>女

四、根据值设置radio选中

复制代码 代码如下:
$("input[name='radio_name'][value='要选中Radio的Value值']").attr("checked",true);  //根据Value值设置Radio为选中状态

五、使用prop方法操作示例

复制代码 代码如下:
$('input').removeAttr('checked');
$($('#'+id+'input').eq(0)).prop('checked',false);
$($('#'+id+' input').eq(0)).prop('checked',true);

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/102976.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号