【问题标题】:Remove immediate newlines删除立即换行符
【发布时间】:2014-03-30 11:43:56
【问题描述】:

删除注释行后,我的输出格式非常糟糕。

我想删除剩下的换行符。

HTML

<html>




<div class="donottouch">
</div>


</html>

我想变成这样

想要的输出

<html>
<div class="donottouch">
</div>
</html>

不输入其他div。

我用来删除注释行的代码:

$('> *', $content).contents().each(function() {
    if (this.nodeType == 8) {
        $(this).remove()
    }
});

非常感谢您!

最好的问候,

亚历克斯

【问题讨论】:

  • 你为什么要这样做?你真的没有得到/失去任何东西……

标签: jquery regex comments newline nodes


【解决方案1】:

您可能想看看jQuery.trim() utilitiy:

说明:

删除字符串开头和结尾的空格。 $.trim() 函数从提供的字符串的开头和结尾删除所有换行符、空格(包括不间断空格)和制表符。如果这些空白字符出现在字符串的中间,它们会被保留。

示例:

删除字符串开头和结尾的空格:
$.trim(" hello, how are you? ");

结果:
"hello, how are you?"

【讨论】:

    猜你喜欢
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-29
    • 2020-01-26
    • 1970-01-01
    • 2012-10-23
    • 1970-01-01
    相关资源
    最近更新 更多