使用jquery查找id的确切位置号

使用jquery查找id的确切位置号,jquery,indexing,find,position,Jquery,Indexing,Find,Position,我使用OWL转盘2,需要幻灯片编号来删除幻灯片,包括: $(".owl-cover-banner").owlCarousel('remove', SLIDENUMBER).owlCarousel('update'); 如何从html代码中获取SLIDENUMBER,而不考虑克隆了class=owl项的div。在这个HTML结构中,class=profilecoverimagebanner_26需要输出0,class=profilecoverimagebanner_25需要输出1 该id已存在为

我使用OWL转盘2,需要幻灯片编号来删除幻灯片,包括:

$(".owl-cover-banner").owlCarousel('remove', SLIDENUMBER).owlCarousel('update');
如何从html代码中获取SLIDENUMBER,而不考虑克隆了class=owl项的div。在这个HTML结构中,class=profilecoverimagebanner_26需要输出0,class=profilecoverimagebanner_25需要输出1

该id已存在为

$(".profilecoverimagebanner_" + id)
这是我的HTML结构:

<div class="owl-stage-outer">
    <div class="owl-stage" style="transition: all 0.25s ease 0s; width: 5910px; transform: translate3d(-2955px, 0px, 0px);">
        <div class="owl-item cloned" style="width: 1182px;">
            <div class="profilecoverimagebanner_26">
                <img class="img-fluid-cover" src="/storage//5/cover/1567847731_5d737533869b0_thumbnail.jpg" alt="">
            </div>
        </div>
        <div class="owl-item cloned" style="width: 1182px;">
            <div class="profilecoverimagebanner_26">
                <img class="img-fluid-cover" src="/storage//5/cover/1567847731_5d737533869b0_thumbnail.jpg" alt="">
            </div>
        </div>
        <div class="owl-item" style="width: 1182px;">
            <div class="profilecoverimagebanner_26">
                <img class="img-fluid-cover" src="/storage//5/cover/1567847731_5d737533869b0_thumbnail.jpg" alt="">
            </div>
        </div>
        <div class="owl-item" style="width: 1182px;">
            <div class="profilecoverimagebanner_25">
                <img class="img-fluid-cover" src="/storage//5/cover/1567847731_5d737533869b0_thumbnail.jpg" alt="">
            </div>
        </div>
        <div class="owl-item cloned active center" style="width: 1182px;">
            <div class="profilecoverimagebanner_26">
                <img class="img-fluid-cover" src="/storage//5/cover/1567847731_5d737533869b0_thumbnail.jpg" alt="">
            </div>
        </div>
        <div class="owl-item cloned active" style="width: 1182px;">
            <div class="profilecoverimagebanner_26">
                <img class="img-fluid-cover" src="/storage//5/cover/1567847731_5d737533869b0_thumbnail.jpg" alt="">
            </div>
        </div>
    </div>
</div>

在没有克隆幻灯片的情况下进行筛选,循环浏览这些幻灯片并从循环中获取索引,而不是元素,这将生成原始索引

常数id=25; 常量幻灯片=$'.owl项'.not'.cloned'; 让我们滑动索引; slides.eachFunction索引{ 如果$`.profilecoverimagebanner${id}`,则此.length{ slideIndex=索引 } } console.logslideIndex
您必须决定要从哪个类中删除多少张幻灯片,然后执行$.profilecoverimagebanner_26:eq+number+。删除您的代码可以很好地处理现有幻灯片。如果我通过ajax添加幻灯片,您的代码将找不到它,而我将无法定义它,这是因为我的代码只是为您指明了正确的方向。无论是否添加了幻灯片,每次需要获取索引时都可以将其包装在函数中,传入id并调用该函数。