我正在尝试使用模板字符串来更新infoDiv的文本,由于某种原因,所有这些文本都在一行中。我究竟做错了什么? these解决方案都不起作用-它们只是呈现出来的。
infoDiv.textContent = `Hi!
It's a ${counter} question quiz.
It takes about ${time_minutes} minutes to solve it.
Are you ready?`
编辑:
我找到了CSS解决方案here(
white-space: pre-line;
)。let counter = 8;
let time_minutes = 3;
infoDiv.textContent = `Hi!
It's a ${counter} question quiz.
It takes about ${time_minutes} minutes to solve it.
Are you ready?`
<div id="infoDiv" style="white-space: pre-line"></div>
最佳答案
使用white-space
CSS属性设置div的样式。
const counter = 22;
const time_minutes = 60;
infoDiv.textContent = `Hi!
It's a ${counter} question quiz.
It takes about ${time_minutes} minutes to solve it.
Are you ready?`
<div id="infoDiv" style="white-space: pre-wrap"></div>