我有一个大的模板的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