单选框选中

<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) 单选选中

猜你喜欢

转载自www.cnblogs.com/mmh760/p/10782273.html