浏览插入数字的div列表

时间:2014-06-26 16:29:27

标签: jquery

我想使用JQuery将索引号添加到我拥有的一组div中:

<div data-product-hotspot-pid="hbeu50220311"></div>
<div data-product-hotspot-pid="hbeu50220311"></div>
<div data-product-hotspot-pid="hbeu50220311"></div>
<div data-product-hotspot-pid="hbeu50220311"></div>

这样就变成了这个:

  <div data-product-hotspot-pid="hbeu50220311">1</div>
    <div data-product-hotspot-pid="hbeu50220311">2</div>
    <div data-product-hotspot-pid="hbeu50220311">3</div>
    <div data-product-hotspot-pid="hbeu50220311">4</div>

这些div也是从下划线的模板动态加载的,所以有没有办法这样:

$( ".swiper-wrapper" ).html(
_.template(template, {looks:looks})

);

那么在我们添加索引号之前有没有办法等到这个完成? 谢谢!

1 个答案:

答案 0 :(得分:1)

附加数据后,您可以使用:

 $(".swiper-wrapper div").each(function(i){
    $(this).text(i+1);
 });

<强> Working Demo