[英]jquery checkbox change,click event not working with jQuery1.8.2
I have a simple js where i am showing an alert on click or change event of checkbox. 我有一个简单的js,在其中我对复选框的单击或更改事件显示警报。 I am using jquery-1.8.2.js library file.
我正在使用jquery-1.8.2.js库文件。 The code is working fine in jsFiddle but its not working elsewhere.
该代码在jsFiddle中工作正常,但在其他地方无法正常工作。 I am unable to figure out what could be the issue here.
我无法弄清楚这里可能是什么问题。
<input type="checkbox" id-="chkJS"/><label for "chkJS">click this</label>
$(document).ready(function(){
$('#chkJS').change(function(){
alert("changed it");
});
$('#chkJS').click(function(){
alert("clicked it");
});
});
You forget =
in label declaration and id-="chkJS"
for input type. 您会忘记标签声明中的
=
和输入类型的id-="chkJS"
。
<input type="checkbox" id="chkJS"/><label for="chkJS">click this</label>
OR 要么
Your code working fine in fiddle
because fiddle load jQuery automatically for you and at other you might not load jQuery. 您的代码可以在
fiddle
正常工作,因为小提琴会自动为您加载jQuery,否则您可能不会加载jQuery。
So please check if jQuery loaded or not. 因此,请检查jQuery是否已加载。
you have a typo in your input element of id-="chkJS"
attribute. 您在
id-="chkJS"
属性的输入元素中有错字。 it should be like this 应该是这样
<input type="checkbox" id="chkJS"/><label for="chkJS">click this</label>
Demo : CheckBox demo 演示: CheckBox演示
id-="chkJS"
应该
id="chkJS"
You code the element was having an hyphen for the id attribute, like id-=, so when the selector searches for the element there is no id for that element. 您编码的元素具有id属性的连字符,例如id- =,因此,当选择器搜索元素时,该元素没有id。 Please change it as follows,
请如下更改
<script src="https://www.google.com/jsapi"></script>
<script>
google.load('jquery', '1.3.1');
</script>
<body>
<input type="checkbox" id="chkJS"/><label for "chkJS">click this</label>
<script>
$(document).ready(function(){
$('#chkJS').change(function(){
alert("changed it");
});
$('#chkJS').click(function(){
alert("clicked it");
});
});
</script>
</body>
I hope it helps. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.