【发布时间】:2016-12-10 11:05:41
【问题描述】:
我的情况(编辑):
<div class="entry-content">
<h1>This header won't be included</h1>
Write by: Me
<br></br>
On: 01/01/2017
<br></br>
<br></br>
When you quote: "<i>And whoever strives only strives for [the benefit of] himself.</i>"
<br></br>
<br></br>
<i>There</i> is another: "And that <b>there is not for man</b> except that [good] for which he strives, and that his effort is going to be seen, then <a href="#">he will be</a> recompensed for it with the fullest recompense."
<br></br>
<br></br>
<h2>And neither will this one</h2>
I fight for myself.
</div>
我的目标(编辑):
<div class="entry-content">
<h1>This header won't be included</h1>
<p>Write by: Me
<br></br>
On: 01/01/2017</p>
<p>When you quote: "<i>And whoever strives only strives for [the benefit of] himself.</i>"</p>
</p><i>There</i> is another: "And that <b>there is not for man</b> except that [good] for which he strives, and that his effort is going to be seen, then <a hre="#">he will be</a> recompensed for it with the fullest recompense."</p>
<h2>And neither will this one</h2>
<p>I fight for myself.</p>
</div>
我试过了:
$( ".entry-content" )
.contents()
.filter(function() {
return this.nodeType === 3;
})
.wrap( "<p></p>" )
.end()
.filter( "br" )
.remove();
我以前也读过很多这样的文章:How can I wrap text nodes。但是他们无法处理<i>、<b>、<a>等。
它们看起来像这样:
<div class="entry-content">
<p><h1>This header won't be included</h1></p>
<p>Write by: Me</p>
<p>On: 01/01/2017</p>
<p>When you quote: "</p>
<i>And whoever strives only strives for [the benefit of] himself.</i>
<p>"</p>
<i>There</i>
<p>is another: "And that <b>there is not for man</b> except that [good] for which he strives, and that his effort is going to be seen, then</p>
<a hre="#">he will be</a>
<p>recompensed for it with the fullest recompense."</p>
<p><h2>And neither will this one</h2></p>
<p>I fight for myself.</p>
</div>
【问题讨论】:
-
既然两者的渲染完全一样,你为什么要这么做?
标签: javascript jquery html tags