jQuery没有单击radiobutton
我的代码:
$(document).ready(function(){ alert("document ready"); $("input[type=radio]").click(function(event){ alert("clicked"); }); });
但没有警报出现……而且,当在控制台上输入时:
$(document).ready(function(){ alert("document ready");})
我收到警报! 这里发生了什么?
尝试.change()而不是.click ()
$(document).ready(function(){ alert("document ready"); $("input[type=radio]").change(function(){ alert("clicked"); }); });
我找到了解决方案,它解释了为什么它在JSFiddle中工作。
问题是我如何导入jQuery:我做到了
它必须是
我不知道为什么会这样,但现在它有效。 谢谢你的努力。
$(function(){ $("input[type='radio']").click(function(){ alert("clicked"); }); });
示例http://jsfiddle.net/Dw6Fp/2/
根据jQuery选择器docs [ link ],你应该用双引号括起参数值:
$('input[type="radio"]').click(function(event){
要么
$("input[type=\"radio\"]").click(function(event){
更新: JSFiddle示例