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';
});
Here's the fiddle: http://jsfiddle.net/DNUdv/
这可能有所帮助。
$("input:checked").removeAttr("checked");
You can use a unique id for each radio button like:
<input type="radio" name="rdo1" id="rdo1_a" value="a" checked="checked" />
Now in the function:
function ResetRdo() {
$("#rdo1_a").attr('checked') == 'checked';
}
Use the same case for each set.
You can give id for check boxes then do
function reset(){
$("#id").attr('checked', 'checked');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.