【发布时间】:2015-12-16 23:24:50
【问题描述】:
如何使用 jQuery 或纯 JavaScript 删除下面代码中 <nospc/> 标记前后的空格? (我意识到我可以简单地手动删除空格,但有时在不呈现的 HTML 中使用空格和换行符会很方便。)
<div>
<img src="" /><nospc/>
<img src="" />
</div>
在完美的世界中,<nospc/> 将删除其自身前后的所有空白,<nospc> ... </nospc> 将删除标记对之间的所有空白。
【问题讨论】:
-
<nospc/>真的是标签吗? -
你尝试了什么?
-
$("nospc").empty() 将删除 nospc 中的所有内容,但我在上面的代码中没有看到打开的 nospc 标记..
-
我不会使用 JavaScript 方法,而是使用 HTML 注释方法。更多信息在这里:css-tricks.com/fighting-the-space-between-inline-block-elements
标签: javascript jquery html