html - Json 结果到 html(换行符)

标签 html json

如果我将以下字符串设置到一个 div 中,我怎样才能让换行符在 HTML 中工作?

{
"s":"Phrase1.\n\nPhrase2"
}

谢谢。

最佳答案

将预先格式化的文本包裹在

 标签中:

<pre>{ "s":"Phrase1.\n\nPhrase2" }</pre>

显示为:

{ "s":"Phrase1.

Phrase2" }

Edit: Another option would be to set the div's style or class to behave the same as a pre tag:

<div style="whitespace:pre"/>

关于html - Json 结果到 html(换行符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4580193/

相关文章:

html - Bulma 上的居中和右对齐导航。移动设备问题

HTML - 如何调用这样的显示?

java - Jackson - 反序列化为不同类型

Swift 3 上的 JSON 图像

html - Webkit/Blink 浏览器不遵守图例标签上的显示样式

python - 无法使用 BeautifulSoup 解析表

html - 继续 div 元素越过水平溢出

c# - 必需的数字参数在不包含在 JSON 中时默认为 0

arrays - 要构造的字符串数组

javascript - 使用 RegEx 从 URL 获取文件扩展名,以便返回正确的内容类型 - 好的做法吗?