任何人都可以给我一些想法如何用<div>每个<h2>标签包装任何内容并给它一个唯一的id,用jquery完成?
我试着这样做:
<h2>Test</h2>
<div id="wrap_1"> // This is the wrapper im trying to add
<p>Bla bla</p>
<p>More Bla bla</p>
</div>
<h2>Another test</h2>
<div id="wrap_2"> // This is the wrapper im trying to add
<p>Bla bla</p>
<p>More Bla bla</p>
</div>
Run Code Online (Sandbox Code Playgroud)
提前致谢
像这样:
$('h2').each(function(index) {
$(this).nextUntil('h2').wrapAll('<div id="wrap' + index + '"></div>');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
709 次 |
| 最近记录: |