我有以下几点:
<form id="myform">
<input type="checkbox" name="check1" value="check1">
<input type="checkbox" name="check2" value="check2">
</form>
如何使用jQuery捕获在myform
中发生的任何检查事件,并知道哪个复选框被切换(并知道它是被打开还是关闭)?
发布于 2010-08-10 01:01:37
$('#myform :checkbox').change(function() {
// this will contain a reference to the checkbox
if (this.checked) {
// the checkbox is now checked
} else {
// the checkbox is now no longer checked
}
});
发布于 2010-08-10 01:04:04
使用change事件。
$('#myform :checkbox').change(function() {
// this represents the checkbox that was checked
// do something with it
});
发布于 2010-08-10 01:02:29
$('#myform input:checkbox').click(
function(e){
alert($(this).is(':checked'))
}
)
https://stackoverflow.com/questions/3442322
复制相似问题