String that contains line breaks

Possible Duplicate:
How to create multiline strings

I have a lot of strings that I want to put in variables, but there is line breaks that aren't accepted.

Firefox says "Unterminated string literal" when I write :

var a="foo
bar";

Is there a way to write my strings without removing the line breaks manually?


If this is not acceptable:

var a="foo" +
"bar";

Or as @minitech (the new mod) suggested:

var a="foo 
bar";

Then the answer is no.


Is this script generated dynamically by a web server?

If so, this web server will need to convert line breaks to the n escape sequence instead. You'll also have the same issue with other reserved characters, such as the backslash and double-quotes.

Some languages allow you to literally write a string constant (such as the @ prefix in C#), however Javascript has no such feature standard, thus certain characters must be escaped.

链接地址: http://www.djcxy.com/p/30452.html

上一篇: 发生短路时未闭合的字符串错误

下一篇: 包含换行符的字符串