jquery javascript:选择单选按钮时采取行动

问题描述:

我有以下单选按钮,其中没有一个默认选中。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"); 
}); 

这对我来说很好。你是否很好地引用了jQuery库?

+2

它看起来就像是东西这条线以上的错误,它搞砸了整个JavaScript的下方。 – Chris 2009-11-07 18:15:48

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

你有TREID onChange事件?

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

尝试代码周围下方线条

$(document).ready(function(){ 

} 
); 

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