javascript 在不使用 HTML 的情况下编码字符串中的换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11657546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Encoding a line break in a string without using HTML
提问by allenylzhou
Is there a way to encode a line break into a string without using any HTML entities or tags? Specifically, I would like a string that I pass into the dojox.gfx renderer to display a line break.
有没有办法在不使用任何 HTML 实体或标签的情况下将换行符编码为字符串?具体来说,我想要一个传递给 dojox.gfx 渲染器的字符串来显示换行符。
回答by ckg
You can escape it with \n
or \u000A
, see:
您可以使用\n
或将其转义\u000A
,请参阅:
How do I break a string across more than one line of code in JavaScript?