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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:55:41  来源:igfitidea点击:

Encoding a line break in a string without using HTML

javascriptstringdojoline-breaksgfx

提问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 \nor \u000A, see:

您可以使用\n或将其转义\u000A,请参阅:

How do I break a string across more than one line of code in JavaScript?

如何在 JavaScript 中的多行代码中拆分字符串?