Javascriptを使用して、考えられるすべての要素の中から「swiper-active-switch」属性を含む要素を見つけて、それが含まれているスパン要素を返してもらいたいと思います。
<span class="swiper-pagination-switch"></span>
<span class="swiper-pagination-switch"></span>
<span class="swiper-pagination-switch"></span>
<span class="swiper-pagination-switch"></span>
<span class="swiper-pagination-switch swiper-visible-switch swiper-active-switch"></span>
<span class="swiper-pagination-switch"></span>`
スパンのカウントを取得する方法は次のとおりですが、それらを反復処理して目的の属性を見つけ、ソースコードでそれが占める行を見つける方法がわかりません。上記の例では、5行目です。たとえば、値「5」を取得したいと思います。
試してください:
var counter = $(this).find("span").length; //full number
alert(counter);
var total = 0;
var hhh = $(this).html();
alert(hhh);
$("span").each(function(){
var n = parseInt($(this).text());
if(n > 0){ //check if element is greater than 0
total ++;
}
});
total = total + 2;
var index = $(".swiper-pagination-switch").index()+2;
alert("total:"+total+" current:"+index);
//and now the actual number for an active page.
$('span.swiper-pagination-switch').index($('.swiper-visible-switch'))
結果が得られます。これは、インデックスが0であるため、4です。必要に応じて、プラス1を加えます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加