我的 html 的类总是根据其中的元素数量而有所不同(ul>li sf-single-children-*
... *
)我如何*
用 javascript 得到这个,所以我可以根据这个数字设置样式?
示例代码:
<ul class='someclass'>
<li class="sf-single-children-* some-other-classes-here-aswell">
<ul style="width: * ">
<li>Item with no children element</li>
<li>Item with no children element</li>
<li>Item with no children element</li>
<li>Item with no children element</li>
<li>Item with no children element</li>
<li>Item with childer element which should not be counted
<ul>
<li>Item with no children element</li>
<li>Item with no children element</li>
<li>Item with no children element</li>
</ul>
</li>
</ul>
</li>
</ul>
另一种方法是我如何做到这一点,它只在父级中计数元素<ul>
但我不知道该怎么做