使用jQuery重置单选按钮 [英] Reset radio button using jQuery

查看:125
本文介绍了使用jQuery重置单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个单选按钮。在检查或随机选择单选按钮值后,我需要将单选按钮重置为默认选中或按钮单击时的选定值。我的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 ?
}



HTML



HTML

<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重置单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆