可能重复:
a more graceful multi-line javascript string method
Multiline strings in Javascript为什么我不能将多行值存储到JavaScript文字中?
window.lastSavedContents = "test
tester";
这是我的JavaScript代码。我得到一个萤火虫错误说:
未结束的字符串[打破 此错误] window.lastSavedContents = “测试
可能重复:
a more graceful multi-line javascript string method
Multiline strings in Javascript为什么我不能将多行值存储到JavaScript文字中?
window.lastSavedContents = "test
tester";
这是我的JavaScript代码。我得到一个萤火虫错误说:
未结束的字符串[打破 此错误] window.lastSavedContents = “测试
事实上,这根本就不是有效的语法使用。‘\ n’来代表换行符:
window.lastSavedContents = "test\n\ntester";
你可以连接它,当然:
var stringTxt = "";
stringTxt += "test";
stringTxt += "tester";
window.lastSavedContents = stringTxt;
但我想保留换行符 – Shamoon 2011-05-27 13:30:58
使用数组并将它连接到字符串是'更好'的。 – 2011-05-27 13:31:10
产生'testtester'这是不是什么操作 – epascarello 2011-05-27 13:40:08
如果你想在JavaScript值,以纪念新行,你个人有T通过把\n
放有一个换行符:
var test = "test\n\ntest";
您也可以直观地通过逃逸线的终端这样的揭露新线:
var test = "test\n\
\n\
test";
嗨,老兄!他们显然是让任何人进来,而且根据我的情况,也没有任何邪恶的计划。 – 2011-05-27 13:43:30
@epas:什么问题?他的回答中我没有看到任何邪恶的东西。 – 2011-05-27 13:47:23
@Marcel,这是一个内部的笑话。 – epascarello 2011-05-27 15:29:33