input 单选按钮radio 取消选中

时间:2022-10-17 14:40:35

input单选按钮: 在radio按钮中添加属性tag  0代表未被选中

<input name="rdo1" value="AA" type="radio" tag="0" />A
        <br />
        <input name="rdo2" value="BB" type="radio" tag="0" />B
        <br />
        <input name="rdo3" value="CC" type="radio" tag="0" />C

jquery:

$(":radio").click(function () {
                var r = $(this).attr("name");
                $(":radio[name=" + r + "]:not(:checked)").attr("tag", 0);
                if ($(this).attr("tag") == 1) {
                    $(this).attr("checked", false);
                    $(this).attr("tag", 0);
                }
                else {
                    $(this).attr("tag",1);
                }
            });