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