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