我在一个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中。我要怎么做才能做到这一点呢?
发布于 2016-03-28 09:46:24
默认情况下,文本节点中的空格是折叠的。对换行符使用<br />或<br>,或者将white-space: pre;添加到该元素的css。
https://stackoverflow.com/questions/36254427
复制相似问题