问题
my code:
$(document).ready(function(){
alert("document ready");
$("input[type=radio]").click(function(event){
alert("clicked");
});
});
But no alert shows up... And, when typing in on the console:$(document).ready(function(){ alert("document ready");})
I get the alert! What is going on here?
回答1:
try .change() instead of .click()
$(document).ready(function(){
alert("document ready");
$("input[type=radio]").change(function(){
alert("clicked");
});
});
回答2:
I found the solution, it explains as well why it does work in JSFiddle.
The problem was how I imported jQuery: I did
<script type="text/javascript" src="jQuerylink" />
and it had to be
<script type="text/javascript" src="jQuerylink" ></script>
I don't know why this is so, but now it works. Thanks for all effort.
回答3:
$(function(){
$("input[type='radio']").click(function(){
alert("clicked");
});
});
Example http://jsfiddle.net/Dw6Fp/2/
回答4:
According to the jQuery selector docs [link] you should enclose parameter value with double quotes:
$('input[type="radio"]').click(function(event){
OR
$("input[type=\"radio\"]").click(function(event){
UPDATE: JSFiddle example
来源:https://stackoverflow.com/questions/9751035/jquery-not-working-on-clicking-radiobutton