jQuery替换为\ n,而HTML不会渲染<br/>

时间:2017-02-03 16:04:03

标签: html

我已经设法用postgresql db替换所有\n<br>。我需要一个TextAreaField来显示换行符。

问题是,文本已被替换,但所有<br>都不会呈现为HTML元素:

enter image description here

这就是我的替代方式:

$('.js-make-please-br').text($('.js-make-please-br').text().replace(/\n/g, "<br>"));

在HTML中:

enter image description here

1 个答案:

答案 0 :(得分:3)

尝试使用jQuery的.html()方法来设置内容:http://api.jquery.com/html/

<强>解决方案:

将第一个text()更改为html()

$('.js-make-please-br').html($('.js-make-please-br').text().replace(/\n/g, "<br>"));