我有一個大的模板的JS文件(使用ES6標準)看起來類似於文字:多行模板字符串轉換爲HTML不包括換行符
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中。我需要做些什麼才能做到這一點?
'white-space:pre;'? – elclanrs
@elcanrs啊真棒,謝謝! '白色空間:預包裝;'是我所需要的。 :) –
'stringLiteral.replace(/ \ n/g,'
')'? – loganfsmyth