如果我将以下字符串设置到一个 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/