gpt4 book ai didi

javascript - JavaScript 字符串中的新行

转载 作者:行者123 更新时间:2023-11-28 15:05:57 25 4
gpt4 key购买 nike

我看到了一些有关如何在 JavaScript 字符串中添加新行的问题。他们中的大多数人建议使用 \n 。我尝试过,但新行未插入到我的 HTML 中。

相反,我得到以下内容:

<strong>This is the first line 
This is the second line</strong>

这是我的字符串:

var myString = "This is the first line \n This is the second line";

<强> Example

知道如何在 HTML 中插入
吗?

最佳答案

如果你想在 html 中添加新行,你需要一些像 <br /> 这样的元素。事实上,每个 block 样式的元素都可以,但是<br />默认情况下不会添加任何边距/填充,如 f.我。一个<p><h3>会。不管怎样,断行 html 需要任何元素,因为浏览器会忽略“\n”、“\t”等。

关于javascript - JavaScript 字符串中的新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38941676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com