码迷,mamicode.com
首页 > Web开发 > 详细

jquery解决input[type=radio]点击选中取消

时间:2018-01-16 11:15:33      阅读:1648      评论:0      收藏:0      [点我收藏+]

标签:rip   jquery   jquer   代码   highlight   als   inpu   body   his   

input[type=radio] 点击选中后,再次点击选中项,默认是不会取消的。用jquery实现点击选中取消的代码:

  

<input type="radio" name="hobby"> 篮球
<input type="radio" name="hobby"> 足球
<input type="radio" name="hobby"> 网球

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

});

  

jquery解决input[type=radio]点击选中取消

标签:rip   jquery   jquer   代码   highlight   als   inpu   body   his   

原文地址:https://www.cnblogs.com/wlgz/p/8295401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!