Possible Duplicates:
a more graceful multi-line javascript string me开发者_如何学Pythonthod 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 = "test\n\ntester";
If you want to mark new line in a JavaScript value you have t put there a newline character by putting \n
:
var test = "test\n\ntest";
You can also visually expose new lines by escaping ends of lines like this:
var test = "test\n\
\n\
test";
http://jsfiddle.net/grcLH/1/
You can concatenate it, of course:
var stringTxt = "";
stringTxt += "test";
stringTxt += "tester";
window.lastSavedContents = stringTxt;
精彩评论