我在JS文件(使用ES6标准)中有一个大型模板文字,看起来类似于:
let stringLiteral = `this is a large
string and it also
has many lines in it
and this is a larger line break`
并将其放入我的HTML文件中,我只是使用:
document.getElementById('content').innerHTML = stringLiteral;
但是,当我这样做时,换行符不会包含在HTML中。我该怎么做才能实现这一目标?
答案 0 :(得分:2)
默认情况下,文本节点中的空格会折叠。使用<br />
或<br>
表示换行符,或将white-space: pre;
添加到该元素的CSS中。