假设您有一个类似的列表:
<ol>
<li>Some text<input type="checkbox" /><input type="checkbox" /></li>
<li>Some text<input type="checkbox" /><input type="checkbox" /></li>
</ol>
我需要查看列表项中有多少个复选框被选中,并且只有当两个复选框都被选中时才执行某些操作。
$(document).ready(function(
$("input:checkbox").click(function() {
if ($(this).parent().children("input:checkbox") == checked) {
do something;
}
});
});
到目前为止,我已经找到了在整个文档中检查数字的方法,并且可以让它告诉我是否检查了“this”。我感谢任何人可以提供的任何帮助。谢谢。
最佳答案
$(document).ready(function(
$("input:checkbox").click(function() {
if ($(this).parent().children("input:checked").length==2) {
do something only if 2 are selected;
}
});
});
关于javascript - jQuery:查找被单击对象的父级中选中的子级的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22081125/