如何在克隆时更改ID? 例: div id="unique" class="cloneMe"test/divdiv id="unique1" class="cloneMe"test/divdiv id="unique2" class="cloneMe"test/div 脚本 jQuery('.cloneMe').clone(); // has all selected after cloning ... 结果 div
例:
<div id="unique" class="cloneMe">test</div> <div id="unique1" class="cloneMe">test</div> <div id="unique2" class="cloneMe">test</div>
脚本
jQuery('.cloneMe').clone(); // has all selected after cloning ...
结果
<div id="unique" class="cloneMe">test</div> <div id="unique1" class="cloneMe">test</div> <div id="unique2" class="cloneMe">test</div> <div id="unique" class="cloneMe">test</div> <div id="unique1" class="cloneMe">test</div> <div id="unique2" class="cloneMe">test</div>
我怎样才能明确修改克隆的div?
您可以使用每个,然后设置一个新的ID.jQuery('.cloneMe').clone().each(function(i){ this.id = "id"+ i; // to keep it unique }).appendTo("someSelector");