javascript - 带 aria-label 的 Owl Carousel 2.2 点

标签 javascript jquery owl-carousel

我想使用“aria-label”来增强 Owl Carousel 中的点,其中包括当前显示的图像。最终代码应如下所示:

<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 标签内的当前图像编号。 Owl Carousel 有计数器或 currentIndex 吗?我怎样才能添加它?感谢您的帮助

最佳答案

您可以循环遍历每个点并为其指定循环索引,如下所示:

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

关于javascript - 带 aria-label 的 Owl Carousel 2.2 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41818880/

相关文章:

javascript - Owl Carousel 仅在包含部分焦点时自动播放

javascript - 使用 JavaScript 获取字符串中的第一个整数

javascript - Breeze 无法自动获取元数据

javascript - 如何阻止 asp listview 中的动态侧边栏崩溃?

php - Sql计算2个表的总数

javascript - jquery分页php返回数据

javascript - 触发popstate事件时如何获取上一页的url?

javascript - 为什么变量立即执行窗口对象而不存储它?

javascript - Owl Carousel 2 无法在调整窗口大小上工作

javascript - owl-Carousel 没有停止垂直拖动