2009-11-07 40 views
11

我有以下單選按鈕,其中沒有一個默認選中。jquery javascript:選擇單選按鈕時採取行動

<input type="radio" name="location" value="0" /> home 
<input type="radio" name="location" value="1" /> work 
<input type="radio" name="location" value="2" /> school 

我該如何檢測何時被檢查。我正在尋找類似的點擊,但它不工作

$("input[name=location]").click(function(){ 
    alert("selected"); 
}); 

回答

1

這對我來說很好。你是否很好地引用了jQuery庫?

+2

它看起來就像是東西這條線以上的錯誤,它搞砸了整個JavaScript的下方。 – Chris 2009-11-07 18:15:48

10
$('input[name=location]').change(function(){ 
    alert(this.checked); 
}); 
2

你有TREID onChange事件?

$("input[name=location]").bind('change', function(){ 
    alert("selected"); 
}); 
3

嘗試代碼周圍下方線條

$(document).ready(function(){ 

} 
); 
1
$(document).ready(function(){ 
    $("input[name=location]").bind('change', function(){ 
    alert("Hello!"); 
    }); 
});