这是我的 html 的基本 View :
<form>
<div id="part1">
// some html form elements including checkboxes
</div>
<div id="part2">
// more html code with more checkboxes
</div>
<div id=part2">
// data table with numerous checkboxes built dynamically
</div
</form>
我需要做的是将 .click()
事件分别绑定(bind)到第 1、2 和 3 部分中的复选框。我已经尝试过这个 $('#part1:checkbox').click(...)
但没有成功。如果我使用 $("form :checkbox").click(...)
相同的点击事件将绑定(bind)到所有复选框,而不仅仅是一组。我该如何分离这些?
最佳答案
你就快到了。您只需要一个空格来分隔后代选择器:
$('#part1 :checkbox').click(function(){
// code goes here
});
为了提高性能,您可能需要使用这个:
$('#part1 input[type=checkbox]').click(function(){
// code goes here
});
关于JQuery 将点击事件绑定(bind)到复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11235966/