我正在尋找一種方法來在javascript中執行多行字符串。我用過這樣的代碼:什麼是javascript反斜槓,它是如何處理多行字符串的?
var str = <><![CDATA[
This string spans multiple lines
Doesn't need quoting of single quotes
And the same goes for "double quotes".
Because of the CDATA, I can also include some <b>html</b>
Which can make use of <attributes with="double quotes"/> but at the same
time, I can make use of the > and < signs without worrying about
xml validity.
]]></>;
在Visual Studio 2012中使用這段代碼時,出現錯誤行。另外,我從來沒有在JavaScript或HTML中使用CDATA,所以我不確定這應該如何工作。
所以,1,這個代碼(有些調整)可以工作嗎? 2,什麼是防滑劑?
JS不支持多行字符串(可能在ES6中?)。只需使用'+'連接。 – Alnitak 2014-10-09 13:38:07
@Alnitak我不喜歡它,我不確定我會認爲它是多行字符串,但是不能在行尾使用反斜槓來繼續下一行?無論哪種方式,我同意在一些可用的瀏覽器中使用級聯 – Ian 2014-10-09 13:40:47
@Ian,但這不是標準。 – Alnitak 2014-10-09 13:42:32