Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.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
Javascript 猫头鹰旋转木马2.2点,带有aria标签_Javascript_Jquery_Owl Carousel - Fatal编程技术网

Javascript 猫头鹰旋转木马2.2点,带有aria标签

Javascript 猫头鹰旋转木马2.2点,带有aria标签,javascript,jquery,owl-carousel,Javascript,Jquery,Owl Carousel,我想用包含当前显示图像的“aria标签”来增强owl转盘中的点。最终代码应如下所示: <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"><sp

我想用包含当前显示图像的“aria标签”来增强owl转盘中的点。最终代码应如下所示:

<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>

但我无法在aria标签中获得当前的图像编号。那里有猫头鹰转盘的计数器或当前索引吗?我如何添加它?感谢您的帮助

您可以在每个点之间循环,并将循环的索引如下所示:

//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);
  });
});

谢谢你的回答,效果很好。我现在唯一的问题是,我在同一个页面上有多个owl转盘,因此下一个库的索引将从上一个库的最后一个编号继续。有没有办法将其重置为零?@webmaya请尝试上面编辑的代码。每次数字应从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);
  });
});