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


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

});

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM