除 textarea 之外的 html 标记,其中 \n 被正确解释 [英] An html tag other than a textarea where \n is correctly interpreted
本文介绍了除 textarea 之外的 html 标记,其中 \n 被正确解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 html 代码:
I have the following html code:
<textarea data-bind="text: signaletic()"></textarea>
信号的来源:
client.signaletic = ko.computed(function () {
var name = ...
var address = ...
var postcode = ...
var city = ...
var country = ...
return name + '\n' + address + '\n' + postcode + ' ' + city + '\n' + country;
});
它有效,我的意思是由于 '\n',我在元素之间有了一条新线.
It works, I mean I have a new line between elements thanks to '\n'.
现在我想使用另一个控件而不是 textarea,我需要一个只读控件.我尝试使用一个简单的 div,但我的 '\n' 不再起作用.有人有想法用只读 html 元素替换我的 textarea ,其中 '\n' 被正确解释吗?
Now I would like to use another control than a textarea, I need a read-only control. I try with a simple div but my '\n' don't work anymore. Does someone have an idea for replacing my textarea with a read-only html element where '\n' is correctly interpreted?
推荐答案
您可以应用 white-space: pre
CSS 属性来强制元素遵守换行符.
You can apply the white-space: pre
CSS property to force an element to respect newlines.
这篇关于除 textarea 之外的 html 标记,其中 \n 被正确解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文