【问题标题】:. Why isn't this string rendered in multiple lines? [duplicate].为什么这个字符串没有以多行呈现? [复制]
【发布时间】:2021-11-16 21:47:28
【问题描述】:

即使我使用了 JavaScript 模板文字,此代码也不会在多行中呈现。为什么会这样?

document.write(`Today is: ${day} 
             The time now is: ${hours} : ${minutes} hrs 
             The year is: ${year}`);

【问题讨论】:

  • 文档被解释为 HTML。 HTML 中的换行符在功能上等同于空格。

标签: javascript multiline template-literals


【解决方案1】:

您缺少一个换行符。或<br> break 用于 html 换行符。添加一两个以获得您想要的。

【讨论】:

  • 感谢您的反馈。换行符
    有效,但换行符 \n 无效。背后有解释吗?
【解决方案2】:

使用\n<br/>标签的换行符

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 2021-12-05
    相关资源
    最近更新 更多