相关疑难解决方法(0)

文本区域中的新行

<textarea cols='60' rows='8'>This is my statement one.\n This is my statement2</textarea>

<textarea cols='60' rows='8'>This is my statement one.<br/> This is my statement2</textarea>
Run Code Online (Sandbox Code Playgroud)

我尝试了两个,但在渲染html文件时新行没有反映出来.我怎样才能做到这一点?

html textarea line-breaks

269
推荐指数
9
解决办法
57万
查看次数

字符串模板 - 新行不显示

我正在尝试使用模板字符串来更新 infoDiv 的文本,由于某种原因,所有这些文本都在一行中。我究竟做错了什么?这些解决方案都不起作用——它们只是被渲染出来的。

infoDiv.textContent = `Hi!
It's a ${counter} question quiz.
It takes about ${time_minutes} minutes to solve it.
Are you ready?`
Run Code Online (Sandbox Code Playgroud)

编辑:

我在这里找到了 CSS 解决方案( white-space: pre-line;)。

infoDiv.textContent = `Hi!
It's a ${counter} question quiz.
It takes about ${time_minutes} minutes to solve it.
Are you ready?`
Run Code Online (Sandbox Code Playgroud)
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?`
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6

0
推荐指数
1
解决办法
2180
查看次数

标签 统计

ecmascript-6 ×1

html ×1

javascript ×1

line-breaks ×1

textarea ×1