我有一个看起来像这样的表格:
<ul id="services">
<li class="service"><label><input type="checkbox">A single option</label>
</li>
<li class="service"><label><input type="checkbox">Another single option</label>
<ul>
<li>
<select>
</select>
additional options</li>
</ul>
</li>
<li class="service"><label>
<select>
</select>
A multiple option</label>
<ul>
<li><label><input type="checkbox"> with another option </label>
<select>
</select>
</li>
</ul>
</li>
<li class="service"><label>
<select>
</select>
Another multiple option</label>
<ul>
<li><label><input type="checkbox"> with another option </label>
<select>
</select>
</li>
<li>
<select>
</select>
additional options</li>
</ul>
</li>
并且我试图通过使用以下方法仅选择具有“服务”类的<label>
s 的第一级中的s:<li>
$(".service label:first-child").css("background", "yellow");
但 is 似乎是递归的,并且正在选择嵌套<ul>
s 的第一个孩子。
我在这里做错了什么?如何仅选择具有“服务”类<label>
的 s 的第一级中的s?<li>