失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > input-radio(单选框)值的获取/默认选中等操作

input-radio(单选框)值的获取/默认选中等操作

时间:2020-10-07 06:29:59

相关推荐

input-radio(单选框)值的获取/默认选中等操作

input-radio(单选框)值的获取/默认选中等操作

由于每一个单选框均为一个单独的input,无法用id直接获取。可通过将一组radio配置为同一个class下,统一管理。

通过class获取input框的选中值:

$("input[name='addusersex']:checked").val()

radio的常用方法:

1.获取选中值,三种方法都可以:

$('input:radio:checked').val();$("input[type='radio']:checked").val();$("input[name='rd']:checked").val();

2.设置第一个Radio为选中值:

$('input:radio:first').attr('checked', 'checked');$('input:radio:first').attr('checked', 'true');注:attr("checked",'checked')= attr("checked", 'true')= attr("checked", true)

3.设置最后一个Radio为选中值:

$('input:radio:last').attr('checked', 'checked');或:$('input:radio:last').attr('checked', 'true');

4.根据索引值设置任意一个radio为选中值:

$('input:radio').eq(索引值).attr('checked', 'true');索引值=0,1,2....或:$('input:radio').slice(1,2).attr('checked', 'true');

5.根据value值设置Radio为选中值:

$("input:radio[value='女']").attr('checked','true');$("input[value='女']").attr('checked','true');

如果觉得《input-radio(单选框)值的获取/默认选中等操作》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。