Owl 轮播 2 从具有特定内容的元素接收项目索引

Owl Carousel 2 receiving item index from element with specific content

谁能告诉我如何从

元素内具有特定内容的元素接收项目索引?

我的商品是这样的:

<div class="item"><img style="position: relative; top: 80px; left: 0px; z-index: 7; width: 27px; height: 27px; opacity: 1!important;" src="someurl" /><img class="thumbimg" style="position: absolute; top: 12px; width: 100%; height: 136px;" src="<?php echo wp_get_attachment_url(get_post_thumbnail_id()) ?>" /><p style="position: relative; top: -25px;"><?php echo get_the_title() ?></p></div>

filter() 方法可让您指定条件。不符合条件的元素从选择中移除,而符合条件的元素将被 returned.This 方法通常用于缩小在一组选定的元素中搜索的元素 elements.Hope 这就是你意思是伙计..:)

$('.item').filter(function() {
    var text = $.trim($(this).find("p").text());
    if(text == "Testing")
    alert("Index = "+($(this).index()+1));
});

Fiddle here

仅供参考

filter