gpt4 book ai didi

javascript - 如何通过js给运行时自动生成的图片应用类

转载 作者:太空宇宙 更新时间:2023-11-03 21:51:06 27 4
gpt4 key购买 nike

这是我在浏览器中看到的Html

<div id="mygallery-paginate"> 
<img src="images/opencircle.png" data-index="0" data-moveto="0" title="" style="cursor: pointer;">
<img src="images/opencircle.png" data-index="1" data-moveto="1" title="" style="cursor: pointer;">
<img src="images/closedcircle.png" data-index="2" data-moveto="2" title="" style="cursor: pointer;">
<img src="images/opencircle.png" data-index="3" data-moveto="3" title="" style="cursor: pointer;">
<img src="images/opencircle.png" data-index="4" data-moveto="4" title="" style="cursor: pointer;">
</div>

我想要这样

<div id="mygallery-paginate"> 
<img src="images/opencircle.png" class="one" data-index="0" data-moveto="0" title="" style="cursor: pointer;">
<img src="images/opencircle.png" class="two" data-index="1" data-moveto="1" title="" style="cursor: pointer;">
<img src="images/closedcircle.png" class="three" data-index="2" data-moveto="2" title="" style="cursor: pointer;">
<img src="images/opencircle.png" class="four" data-index="3" data-moveto="3" title="" style="cursor: pointer;">
<img src="images/opencircle.png" class="five" data-index="4" data-moveto="4" title="" style="cursor: pointer;">
</div>

请提供必要的 CSS/JS

最佳答案

DEMO

var nclasses = ['one','two','three','four','five'];
$('#mygallery-paginate').find('img').each(function(i){
$(this).addClass(nclasses[i]);
});

关于javascript - 如何通过js给运行时自动生成的图片应用类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17338316/

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