這裏,試試這個JS_FIDDLE-DEMO
它檢測父容器上的點擊。不是它自己的單選按鈕。
//listen to click on parent div,span,li for example.
$("#myList-parent").click(function(){
alert('You clicked radio!');
//Now put your logic here. I decide based on the radio button value.
if($('input:radio[name=type]:checked').val() == "UnSelectable"){
alert($('input:radio[name=type]:checked').val());
return false;
}
});
更新(變通適用於Chrome):JS-FIDDLE-DEMO 似乎鉻與on click
問題,所以用on mousedown
更換(或同時使用):
$("input").on("mousedown",function(e) {
e.preventDefault();
if ($(this).is(':checked')) {
alert('This radio button was checked in mousedown');
} else {
alert('This radio button was not checked in mousedown');
}
});
哪裏是你的html ? –
什麼是東西? –
爲簡單起見,東西只是一個布爾變量集之前 –