Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Indexing 父元素中匹配项的索引,即使它们是';re在其他子容器中_Indexing_Parent_Children - Fatal编程技术网

Indexing 父元素中匹配项的索引,即使它们是';re在其他子容器中

Indexing 父元素中匹配项的索引,即使它们是';re在其他子容器中,indexing,parent,children,Indexing,Parent,Children,我需要得到与ul.showreel_缩略图相关的li.play的索引。这可能吗?我似乎只得到ul.row中的li索引 <ul class="showreel_thumbnails"> <li> <ul class="row"> <li class="play_video">item</li> <li class="play_video">item</li>

我需要得到与ul.showreel_缩略图相关的li.play的索引。这可能吗?我似乎只得到ul.row中的li索引

<ul class="showreel_thumbnails">
    <li>
      <ul class="row">
        <li class="play_video">item</li>
        <li class="play_video">item</li>
        <li class="play_video">item</li>
      </ul>
   </li>
    <li>
       <ul class="row">
       <li class="play_video">item 4</li>
       <li class="play_video">item</li>
       </ul>
    </li>
</ul>
    • 项目
    • 项目
    • 项目
    • 第4项
    • 项目
因此,如果第4项被点击,它应该给我4等的索引


最好的,丹。

它可能不是有效的HTML,但下面是它的工作原理(使用JQuery):


HTML不是有效的。UL内部的UL被错误更新。这是否现在有效?是否“我需要”?谢谢,但在“返回项目计数;”“未捕获的SyntaxError:意外令牌返回”之后创建了一个错误。我更新了代码snipet。对不起,我忘了关闭单击功能和。每个功能都应该是我自己发现的。还为if($(this).hasClass(“igotclicked”){return false;}添加了括号,因为似乎没有捕捉到。。。谢谢
function FindMyCount()
{
    var item_count = 0;
    $("#showreel_thumbnails li").each(function() {
        ++item_count;
        if($(this).hasClass("igotclicked"))
            return false;
    });
    return item_count;
}

$("#showreel_thumbnails li").click(function() {
    $(this).addClass("igotclicked");
    var myCount = FindMyCount(); // 1 - the # of li's under the showreel piece
    $(this).removeClass("igotclicked");
    // Do what you want here.
});