0

这是我在浏览器中可以看到的 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 提出建议

4

3 回答 3

2

演示

var nclasses = ['one','two','three','four','five'];
$('#mygallery-paginate').find('img').each(function(i){
    $(this).addClass(nclasses[i]);
});
于 2013-06-27T08:35:01.113 回答
2

尝试:

var classes = ['one', 'two', 'free']; // add more if need
var i = 0;

$('#mygallery-paginate img').each(function(){
     if(!!classes[i++])
         $(this).addClass(classes[i]);
});
于 2013-06-27T08:32:55.270 回答
0

“将类应用于图像”是指什么?每个元素的连续编号?

于 2013-06-27T08:32:42.893 回答