我正在使用此代码段以删除断点 ( <br/>
) 并将我的文本包装在段落中:
$('.articleText').contents().filter(function() {
return this.nodeType == 3;
}).wrap('<p></p>').end().filter('br').remove();
来源:http ://api.jquery.com/contents/
问题是我的文本包含一个未包含在段落中的超链接 () - 它只是被遗漏了......
这是我的文本片段:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. <br/><br/>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a <a href="#">galley</a> of type and scrambled it to make a type specimen book.
这就是它的转变方式:
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a</p>
<a href="#">galley</a>
<p>of type and scrambled it to make a type specimen book.</p>
这应该是这样的:
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a <a href="#">galley</a> of type and scrambled it to make a type specimen book.</p>
这怎么可能...?