首页 > 其他 > 详细

单选框选中

时间:2019-04-28 11:42:52      阅读:123      评论:0      收藏:0      [点我收藏+]

<form id="form1">

<table border="0">
<tr>
<td>年龄段:</td>
<td>
<input type="radio" name="age" value="18" />小于18岁
<input type="radio" name="age" value="18-40" checked="checked" />18-40岁
<input type="radio" name="age" value="40" />40以上
</td>
</tr>
<tr>
<td>分数:</td>
<td>
<input type="radio" name="score" value="60" />小于60分
<input type="radio" name="score" value="60-80" checked="checked" />60-80分
<input type="radio" name="score" value="80" />80分以上
</td>
</tr>
</table>
</form>

jq:

function readradio() {
// jquery 1.3 之后使用(名称相同的radio)
item = $(‘input[name=age]:checked‘).val();
alert(item);
// jquery 1.3 之后使用(所有radio)
$("input[type=radio]:checked").each(function() {
item = $(this).val();
alert(item);

//也可以

$(‘input:radio:checked‘).val();
})

//选中单个单选框(可以在单选框中加入id,然后使用id选择器操作单个单选框的选中)

.prop("checked",false) 单选不选
.prop("checked",true) 单选选中

单选框选中

原文:https://www.cnblogs.com/mmh760/p/10782273.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!