gpt4 book ai didi

jquery - 使用 jQuery 获取嵌套列表项的索引

转载 作者:行者123 更新时间:2023-11-28 13:21:29 24 4
gpt4 key购买 nike

尝试获取包含在事件部分中选择的类的 anchor 标记的列表项的索引号

我要检索的 LI:

<li>
<a href="#" data-id="3" class="scene unchecked selected">The Health Care Delivery System</a>
</li>

在这个例子中我应该得到一个索引 1

<ul>
<li>
<a href="#" class="scene expanded checked">Introduction</a>
</li>
<li class="active-section">
<a class="expanded">The Section 2</a>
<ul style="display: block;">
<li>
<a href="#" data-id="2" class="scene checked">Introduction</a>
</li>
<li>
<a href="#" data-id="3" class="scene unchecked selected">The Health Care Delivery System</a>
</li>
<li>
<a href="#" data-id="4" class="scene unchecked">Determining Payments from External Customers</a>
</li>
<li>
<a href="#" data-id="5" class="scene unchecked">Checkpoint</a>
</li>
</ul>
</li>
<li>
<a class="collapsed">Paying for Health Care</a>
<ul class="collapsed" style="">
<li>
<a href="#" data-id="6" class="scene unchecked">Health Care Systems</a>
</li>
<li>
<a href="#" data-id="7" class="scene unchecked">Find Savings with a Discount</a>
</li>
<li>
<a href="#" data-id="8" class="scene unchecked">Checkpoint</a>
</li>
<li>
<a href="#" data-id="9" class="scene unchecked">Defects in Ice Skate Pairs</a>
</li>
</ul>
</li>
<li>
<a href="#" data-id="22" class="collapsed scene unchecked">Summary</a>
</li>
</ul>

这是我试过的,但是没有用

var innerIndex = $("li.active-section").index("li:has(a.selected)");

最佳答案

$(".active-section li:has(a.selected)").index();

您需要获取正确的 li 元素的索引。

http://jsfiddle.net/ExplosionPIlls/PKEBv/

关于jquery - 使用 jQuery 获取嵌套列表项的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14594387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com