简体   繁体   English

如何保留换行符?

[英]How to preserve line breaks?

On jsp page I get content by ajax and put the result into html 在jsp页面上,我通过ajax获取内容并将结果放入html中

$('#somediv').html(html);

From server side I send content: there is some text,<br/>and from here it starts from the next line 我从服务器端发送内容: there is some text,<br/>and from here it starts from the next line

How to preserve line breaks in page? 如何保留页面中的换行符? Now they display just like text. 现在它们像文本一样显示。

You can use jQuery.parseHTML() 您可以使用jQuery.parseHTML()

var htmlParsed=jQuery.parseHTML(html);
$('#somediv').html(htmlParsed);

In your AJAX call you can specify that you're expecting HTML. 在AJAX调用中,您可以指定要使用HTML。 For example: 例如:

$.ajax({
    url: "your-url.html",
    type: "GET",
    dataType: "html",
    success: function (data) {
        $('#somediv').html(data);
    }
});

See the jQuery docs for more info 有关更多信息,请参见jQuery文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM