假设div内有多个复选框(称为“ startwars”),我知道如何通过以下方式检查或触发功能:如果复选框的状态已更改或在页面上单击以下内容:
$('input[type=checkbox]').click(function() {
console.log("somethign is checked on the page")
});
但是如果我想将该范围限制为div并检查该div内是否有任何复选框状态被更改/单击该怎么办,
如果要更改或单击带有JQuery的div元素中的任何复选框,我想触发一个函数
向您要限制范围的div添加一个类或id,并在jQuery的选择器中使用它
<div class='limited'>
<input type='checkbox' />
</div
JS
$('.limited input[type=checkbox]').change(function() { // while you're at it listen for change rather than click, this is in case something else modifies the checkbox
console.log("something is checked on the page")
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句