这是我在浏览器中看到的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
最佳答案
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/