我需要追加不同div
- s
var thmb_count = thmb_wrap.length;
for( i = 0; i < thmb_count; i++){
var num = i + 1;
thmb_wrap.each(function(){
$(this).append('<span class="numeric">' + num + '/' + (full) + '</span>');
});
}
html
<div class="thumb-wrp scrollbar-inner">
<div class="thm-img"><img src="img/img/a.jpg"></div>
<div class="thm-img"><img src="img/img/b.jpg"></div>
<div class="thm-img"><img src="img/img/c.jpg"></div>
<div class="thm-img"><img src="img/img/d.jpg"></div>
<div class="thm-img"><img src="img/img/a.jpg"></div>
<div class="thm-img"><img src="img/img/c.jpg"></div>
<div class="thm-img"><img src="img/img/b.jpg"></div>
<div class="thm-img"><img src="img/img/d.jpg"></div>
</div>
答案 0 :(得分:2)
您可以迭代thm-img
并附加范围
var $thumbs = $('.thumb-wrp .thm-img'),
full = $thumbs.length;
$thumbs.append(function(i) {
return '<span class="numeric">' + (i + 1) + '/' + (full) + '</span>'
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="thumb-wrp scrollbar-inner">
<div class="thm-img"><img src="img/img/a.jpg"></div>
<div class="thm-img"><img src="img/img/b.jpg"></div>
<div class="thm-img"><img src="img/img/c.jpg"></div>
<div class="thm-img"><img src="img/img/d.jpg"></div>
<div class="thm-img"><img src="img/img/a.jpg"></div>
<div class="thm-img"><img src="img/img/c.jpg"></div>
<div class="thm-img"><img src="img/img/b.jpg"></div>
<div class="thm-img"><img src="img/img/d.jpg"></div>
</div>
&#13;