Why can't I store multi line values into a JavaScript literal?
Possible Duplicates:
a more graceful multi-line javascript string method
Multiline strings in Javascript
window.lastSavedContents = "test
tester";
That's my JavaScript Code. I get a firebug error saying:
unterminated string literal [Break On This Error] window.lastSavedContents = "test
Indeed; that's simply not valid syntax. Use "n" to represent a newline:
window.lastSavedContents = "testnntester";
If you want to mark new line in a JavaScript value you have t put there a newline character by putting n
:
var test = "testnntest";
You can also visually expose new lines by escaping ends of lines like this:
var test = "testn
n
test";
http://jsfiddle.net/grcLH/1/
当然,您可以连接它:
var stringTxt = "";
stringTxt += "test";
stringTxt += "tester";
window.lastSavedContents = stringTxt;
链接地址: http://www.djcxy.com/p/30444.html
上一篇: 将换行符添加到jquery字符串参数