【发布时间】:2012-02-03 10:08:21
【问题描述】:
我有一个 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>
-- 大卫
【问题讨论】:
-
到目前为止你尝试了什么?
-
我尝试使用 .clone jQuery 函数,但它不想工作。
-
请注意,
lielements 仅是ol、ul和menu元素的有效子元素,而不是divs。
标签: javascript jquery html clone nodes