【发布时间】:2013-12-31 05:08:57
【问题描述】:
我现在的脑洞最大……
我需要附加 i 数量的幻灯片(可以为空白),但它们必须具有用于内部 div 的特定类,以及幻灯片名称中由 i 组成的特定 ID。
<ul class="bjqs"><!-- Target This -->
<li id="slide0"><!-- Append these -->
<div class="center"><!-- Append these -->
<span class="author"></span><!-- Append these -->
<span class="time"></span><!-- Append these -->
</div>
<div class="image"></div><!-- Append these -->
</li>
<li id="slide1"><!-- Append these -->
<div class="center"><!-- Append these -->
<span class="author"></span><!-- Append these -->
<span class="time"></span><!-- Append these -->
</div>
<div class="image"></div>
</li>
<li id="slide2">... etc
</ul>
也许基本的for loop 可以工作...?
var slideCount = 20;
for(var i = slideCount-1;i>=0;i--){
$('ul.bjqs').after('<li id="slide'+i+'"><div class="center"><span class="author"></span><span class="time"></span></div><div class="image"></div></li>');
}
(嗯,它确实有效......但是有更清洁的方法吗?)
【问题讨论】:
-
查看模板 [event the basic feature by underscore.js will do]。
标签: javascript jquery html for-loop append