jQuery 复选框 onChange
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11110506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:12:14 来源:igfitidea点击:
jQuery checkbox onChange
提问by Nate Pet
I have a checkbox with an id of activelist
我有一个 ID 为 activelist 的复选框
I tried the following but did not seem to work (I have below in) :
我尝试了以下但似乎没有工作(我在下面):
$(document).ready(function () {
$('#activelist :checkbox').change(function () {
alert('changed');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" id='inactivelist' value="inactivelist" />
回答by mgraph
There is no need to use :checkbox
, also replace #activelist
with #inactivelist
:
没有必要使用:checkbox
,也替换#activelist
为#inactivelist
:
$('#inactivelist').change(function () {
alert('changed');
});
回答by Sparkup
There is a typo error :
有一个拼写错误:
$('#activelist :checkbox')...
Should be :
应该 :
$('#inactivelist:checkbox')...
回答by arul pushpam
$('input[type=checkbox]').change(function () {
alert('changed');
});