【发布时间】:2016-06-24 00:14:10
【问题描述】:
我想检查一个特定元素的所有复选框是否都被选中,但最后一个 我有这种HTML
<ul class="progress-indicator">
<li>
//Others elements (variable)
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox"> // Exclude this one
</li>
<li>
//Stuff here
</li>
<li>
//Another stuff
</li>
</ul>
我第一次尝试过
if($(".progress-indicator > li:first-child").find(":checkbox").length == $(".progress-indicator > li:first-child").find(":checkbox:checked").length)
{
//All checkbox of first li are checked
}
这是可行的,但现在我想排除第一个 li 的最后一个复选框
所以我从那个开始
$(".progress-indicator > li:first-child").find(":checkbox:not(:last-child)").length
但它没有工作。此选择器仅选择第一个 li 的第一个复选框。我认为这是由于我以前拥有的Others elements。 (例如,复选框位于 div 内,该 div 位于另一个元素内。
那么,除了最后一个复选框OF this li 之外,如何选中第一个li 的所有复选框?
【问题讨论】:
标签: javascript jquery selector