猫头鹰旋转木马2.2点与咏叹调标签

时间:2017-01-24 02:09:26

标签: javascript jquery owl-carousel

我想用'aria-label'来增强猫头鹰旋转木马中的圆点,其中包括显示的当前图像。最终代码应如下所示:

<div class="owl-dot" aria-label="1><span></span></div>
<div class="owl-dot" aria-label="2"><span></span></div>
<div class="owl-dot" aria-label="3"><span></span></div>

我正试图用attr方法达到这个目的

    $('.owl-carousel .owl-dot').attr('aria-label', '+currentIndex.lenght+');

但我根本无法在aria标签内获得当前图像编号。猫头鹰旋转木马是否有计数器或currentIndex?我该如何添加它?谢谢你的帮助

1 个答案:

答案 0 :(得分:1)

你可以循环遍历每个点并给它一个循环的索引,如下所示:

//Go through each carousel on the page
$('.owl-carousel').each(function() {
    //Find each set of dots in this carousel
  $(this).find('.owl-dot').each(function(index) {
    //Add one to index so it starts from 1
    $(this).attr('aria-label', index + 1);
  });
});