我想知道如何确定 ul 是否有超过 2 个子级,以及此 ul 内是否有两个具有两个特定类别的子级……
if($(this).children().length > 2 && $(this).children('.section-title, .active')) {
$(this).append('<li class="dots">…</li>');
}
???
最佳答案
var $ul = $('ul');
if($ul.find("li").length > 2 && $ul.find('.active, .inactive').length == 2) {
alert('yes, it is this way');
}
<ul>
<li class="active">Whatever</li>
<li class="inactive">Whatever</li>
<li>Whatever</li>
<li>Whatever</li>
</ul>
关于jquery:如果 child 有特定类(class)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3176190/