[英]Removing html line breaks using Javascript
I'm trying to grab an element's HTML using jQuery and then post it to the server. 我正在尝试使用jQuery获取元素的HTML,然后将其发布到服务器。 I successfully grabbed it, but I am not able to remove the white space between the tags and the line breaks that are rendered by default.
我成功抓住了它,但是我无法删除标签和默认渲染的换行符之间的空白区域。 The HTML code grabbed is shown below:
抓取的HTML代码如下所示:
<table><tbody><tr><th></th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th></tr>
<tr><th>2nd row</th><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tbody></table>
I would like to trim the spaces between the tags only. 我想只修剪标签之间的空格。 I've used this regular expression:
str.replace(/\\s+/g, ' ');
我使用过这个正则表达式:
str.replace(/\\s+/g, ' ');
. 。 But that doesn't seem to work, any suggestions?
但这似乎没有用,有什么建议吗?
Currently, you are replacing all consecutive sequences of whitespace with a single space. 目前,您正在使用单个空格替换所有连续的空白序列。
This is what you want: 这就是你想要的:
str.replace(/>\s+</g, '><');
我需要在每行的末尾添加转义字符(反斜杠 - )字符来包装字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.