换行符被打印为html的文本区域中的空格。如何解决 [英] Newline is being printed as a whitespace in Text Area of html. How do I resolve

查看:262
本文介绍了换行符被打印为html的文本区域中的空格。如何解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的小jquery脚本,其中我附加了我收到的数据。

This is my small jquery script where I append data that I receive.

$.get('HelloWorld', {'data' : data}, function(newLogs) {
    $('#logsid').append(newLogs);
    $('#logsid').scrollTop($('#logsid')[0].scrollHeight);
});


推荐答案

默认情况下,HTML将换行符作为空格空格折叠到一个空格)。将此规则添加到样式表以保留空格...

By default, HTML renders newlines as spaces (and multiple whitespace is collapsed to one space). Add this rule to your stylesheet to preserve whitespace...

#logsid {
    white-space: pre;
}

或者你可以在jQuery ...

Or you can do this in jQuery...

$('#logsid').css("white-space", "pre");

您也可以通过更改 logsid 成为< pre> 元素。

You can also achieve this by changing logsid to be a <pre> element.

这篇关于换行符被打印为html的文本区域中的空格。如何解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆