我有多个单选按钮.随机检查或选择单选按钮值后,我需要在单击按钮时将单选按钮重置为默认选中或选择的值.我的 HTML 代码如下.
I'm have multiple radio button. After check or select radio button value randomly, i need to reset radio button to default checked or selected value on button click. My HTML code is below.
function ResetRdo() {
// Code to reset ?
}
<table>
<tr>
<td>
<input type="radio" name="rdo1" value="a" checked="checked" />
A
<input type="radio" name="rdo1" value="b" />
B
<input type="radio" name="rdo1" value="c" />
C
</td>
</tr>
<tr>
<td>
<input type="radio" name="rdo2" value="1" />
1
<input type="radio" name="rdo2" value="2" checked="checked" />
2
<input type="radio" name="rdo2" value="3" />
3
</td>
</tr>
<tr>
<td>
<input type="radio" name="rdo3" value="1a" />
1a
<input type="radio" name="rdo3" value="2b" />
2b
<input type="radio" name="rdo3" value="3c" checked="checked" />
3c
</td>
</tr>
<tr>
<td>
<input type="button" value="Reset" onclick="ResetRdo()" />
</td>
</tr>
</table>
$('input[type=radio]').prop('checked', function () {
return this.getAttribute('checked') == 'checked';
});
这里是小提琴:http://jsfiddle.net/DNUdv/
这篇关于使用 jQuery 重置单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!