Cur*_*per 3 javascript text-editor line-breaks
在下面的脚本[脚本的一部分]中,
document.write(
'<div class="user-info-wrap">
<div class="user-info-left">'
Run Code Online (Sandbox Code Playgroud)
我的文本编辑器停止对第三行着色,就好像它不包含在单引号中一样。文本编辑器换行符是否结束(javascript 字符串)引用内容?
如果是这样,这意味着我需要执行以下操作,在我看来,这似乎没有意义,因此文本编辑器的着色原理图可能有错误。
document.write(
'<div class="user-info-wrap">' +
'<div class="user-info-left">'
Run Code Online (Sandbox Code Playgroud)
是哪一个?
更新
\n随着 ECMAScript 版本 6 (ES6) 现在成为所有主要浏览器的标准,您不再需要再进行转义技巧。这简直就是 ES5 的一个“技巧”。继续前进,您所需要做的就是将字符串包裹在两个反引号内`。
\nvar multiStr = `This is the first line\nThis is the second line\nThis is more...`;\nRun Code Online (Sandbox Code Playgroud)\n您可以执行以下两项操作之一:
\n级联:
\nvar multiStr = "This is the first line " +\n"This is the second line " +\n"This is more...";\nRun Code Online (Sandbox Code Playgroud)\n逃脱:
\nvar multiStr = "This is the first line \\\nThis is the second line \\\nThis is more...";\nRun Code Online (Sandbox Code Playgroud)\n两者输出:
\n\n\n这是第一行 这是第二行 这是更多...
\n
注意:使用转义方法时,不会忽略连续行上的前导空格。
\nvar multiStr = "This is the first line \\\n This is the second line \\\n This is more...";\nRun Code Online (Sandbox Code Playgroud)\n这将输出:
\n\n\n这是第一行 \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 这是第二行 \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 这是更多...
\n
回答你的问题:
\n并非所有文本编辑器都支持 JavaScript 多行字符串突出显示。Notepad++ 可以很好地处理它,而 VI/VIM 不会将整个字符串显示为红色。VI/VIM 只知道如何突出显示位于左引号所在同一行的字符串。如果您注意到,VI/VIM 会认为您创建了一个新字符串(在最后一行),其中第一个字符是分号。这不是真的,这只是编辑突出显示的一个缺陷。
\n
| 归档时间: |
|
| 查看次数: |
2397 次 |
| 最近记录: |