我正在尝试一个一个地复制一堆 div 并使用以下代码将其粘贴到相应的列表中
var index=1;
$('.storycontent').each(function () {
('#story-tabs ul li:nth-child(n)').after($(this).html());
index++;
});
<ul>
<li class="first current">Story1</li>
<li class="first">Story2</li>
<li class="first">Story3</li>
</ul>
执行上述代码后,我得到的输出是
<ul>
<li class="first current">Story1</li>
<div id="one">some content</div>
<div id="two">some content</div>
<div id="three">some content</div>
<li class="first">Story2</li>
<div id="one">some content</div>
<div id="two">some content</div>
<div id="three">some content</div>
<li class="first">Story3</li>
<div id="one">some content</div>
<div id="two">some content</div>
<div id="three">some content</div>
</ul>
但我需要
<ul>
<li class="first current">Story1</li>
<div id="one">some content</div>
<li class="first">Story2</li>
<div id="two">some content</div>
<li class="first">Story3</li>
<div id="three">some content</div>
</ul>