input 单选按钮radio 取消选中(转载)

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

HTML代码:

<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);
     }
});

 

posted @ 2016-03-18 17:49  奔跑的蜗牛~  阅读(1885)  评论(0编辑  收藏  举报