What is the best possible way to pass a Mulitline String as function argument?
What will be the Best practice to pass Multiline String as a Javascript function's a开发者_运维问答rgument.
You can pass it a variable!
JavaScript strings can contain newline characters, so you don't have to do anything special. (Edit Actually, I suppose you do — you have to use an escape sequence; that's covered below.) Example:
var s = "This is line 1\nThis is line 2\nThis is line 3.";
alert(s);
...alerts
This is line 1 This is line 2 This is line 3
The full syntax of the escape sequences in JavaScript strings is (of course) in the specification, but here's a brief (probably incomplete) rundown:
\n- newline\r- carriage return\t- tab\v- vertical tab\b- backspace\f- formfeed\u0100- Unicode character 256 (e.g., the value is in hex, four digits)\xfd- Unicode character 253 (e.g., the value is in hex, two digits)\\- backslash\"- double quote (useful when you're using double quotes to delimit a string literal)\'- single quote (useful when you're using single quotes to delimit a string literal)
加载中,请稍侯......
精彩评论