如何<p>
从 div 的 html 中删除非文本节点(BR,空标签,nbsp),但仅删除在第一个文本节点出现之前出现的节点。就像从普通字符串中去除前导空格一样,但这里是从 HTML 字符串中删除前导空格。
我尝试过使用正则表达式,但这种方法经常会出现问题。我想用NodeType
JQuery 来做。如果有人有任何例子,请分享。
谢谢!
UPDATE:
采取以下DIV: -
<div id="foo">
<div>
<div>
<p>
</p>
<p>
</p>
<br/>
<p>
this is a test</p>
<p>
</p>
<br />
<br>
<p>
this is a fast test
</p>
</div>
</div>
</div>
将“foo”传递给空格删除函数时,它应该如下所示:-
<div id="foo">
<div>
<div>
<p>
this is a test</p>
<p>
</p>
<br />
<br>
<p>
this is a fast test
</p>
</div>
</div>
</div>