1. 程式人生 > >JavaScript中多行字串變數

JavaScript中多行字串變數

JavaScript中多行字串變數

var htmlString = "<div>This is a string.</div>";

下面是錯誤的:

var htmlSTring = "<div>
  This is a string.
</div>";

新增反斜槓滿足可讀性,使其工作。

var htmlSTring = "<div>\
  This is a string.\
</div>";

https://css-tricks.com/snippets/javascript/multiline-string-variables-in-javascript/