我有一个带有详细信息页面的 MVC3 应用程序。作为其中的一部分,我有一个包含空格和换行符的描述(从数据库检索)。当它被渲染时,新行和空格将被 html 忽略。我想对这些空格和新行进行编码,以便它们不会被忽略。
你是怎样做的?
我尝试了 HTML.Encode 但它最终显示了编码(甚至不在空格和新行上,而是在其他一些特殊字符上)
只需使用内容样式white-space: pre-wrap; https://developer.mozilla.org/en-US/docs/Web/CSS/white-space#Values.
div {
white-space: pre-wrap;
}
<div>
This is some text with some extra spacing and a
few newlines along with some trailing spaces
and five leading spaces thrown in
for good
measure
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)