gpt4 book ai didi

javascript - 如何在动态元素上添加多个类,其中一个类的数字递增?

转载 作者:行者123 更新时间:2023-11-30 21:14:53 34 4
gpt4 key购买 nike

我一直在尝试使用带有自定义类的滑动 slider 来创建一些幻灯片。

<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
<div class="swiper-slide">Slide 4</div>
<div class="swiper-slide">Slide 5</div>
<div class="swiper-slide">Slide 6</div>
<div class="swiper-slide">Slide 7</div>
<div class="swiper-slide">Slide 8</div>
<div class="swiper-slide">Slide 9</div>
<div class="swiper-slide">Slide 10</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
<!-- Swiper JS -->
<script src="../dist/js/swiper.min.js"></script>
<!-- Initialize Swiper -->
<script>
var swiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
paginationClickable: true,
paginationBulletRender: function (swiper, index, className) {
return '<span class="' + className + '">' + (index + 1) + '</span>';
}
});
</script>

滑动分页动态创建并生成

<span class="swiper-pagination-bullet">1</span>
<span class="swiper-pagination-bullet">2</span>
<span class="swiper-pagination-bullet">3</span>
<span class="swiper-pagination-bullet">4</span>
<span class="swiper-pagination-bullet">5</span>
<span class="swiper-pagination-bullet">6</span>

我想让 div 类滑动器分页到

<span class="swiper-pagination-bullet color-0">1</span>
<span class="swiper-pagination-bullet color-1">2</span>
<span class="swiper-pagination-bullet color-2">3</span>

如何添加 color-0、color-1、color-2 的附加自定义类?非常感谢。

最佳答案

return '<span class="'+ className +' color-'+index+'" >'+(index+1)+'</span>';

关于javascript - 如何在动态元素上添加多个类,其中一个类的数字递增?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45786914/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com