如何在javascript中应用换行符

Fly*_*Cat 1 html javascript css

我有一个从数据库中检索的 javascript 对象属性。

它有类似的东西

This is line one
This is line two
This is line three
This is the line four
Run Code Online (Sandbox Code Playgroud)

我的问题是当我想在我的 html 页面中显示它们时,没有断线并且它们都像抽筋一样:

this is line one this is line two this is line three this is the line four
Run Code Online (Sandbox Code Playgroud)

无论如何我只能用Javascript显示换行符吗?

谢谢。

Ger*_*osi 5

将新行 ( \n)替换为<br>标签:

replace(/\n/g, '<br>');
Run Code Online (Sandbox Code Playgroud)

请参阅JSFiddle上的示例