我有一个li element
父级div
与id
holder
。我需要多次克隆li
,将所有克隆都归入holder div
并更改其data-ids
。我的层次结构是这样的:多次克隆一个元素
<div id="holder">
<li data-id=0 class="element">
//other nodes
</li>
</div>
我如何可以克隆li element
,比改变它的data-id
,所以我得到:
<div id="holder">
<li data-id=0 class="element">
//other nodes
</li>
<li data-id=1 class="element">
//other nodes
</li>
<li data-id=2 class="element">
//other nodes
</li>
<li data-id=3 class="element">
//other nodes
</li>
<li data-id=4 class="element">
//other nodes
</li>
<li data-id=5 class="element">
//other nodes
</li>
</div>
- 大卫
你到目前为止做了什么? – 2012-02-03 10:10:12
我试图使用.clone jQuery函数,但它不想工作。 – 2012-02-03 10:12:17
请注意,['li' elements](http://www.w3.org/TR/html5/grouping-content.html#the-li-element)只是'ol','ul'和'menu'元素,而不是'div's。 – 2012-02-03 11:13:39