你可以把换行符显示为中断< br />? [英] Can you make newline characters \n display as breaks <br />?

查看:149
本文介绍了你可以把换行符显示为中断< br />?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用IMAP显示电子邮件。当电子邮件是文本虽然,换行符\\\
不正确显示。我宁愿不把它们转换成中断<因为如果用户想要回复那封电子邮件,那么现在就用HTML而不是纯文本。有没有可能是一个JavaScript函数,可以显示为一个换行符而不改变代码?

解决方案

< pre> 标记中,则会显示所有换行符。或者,您可以通过将CSS样式 white-space:pre 应用于任何元素来达到相同的效果。



不要忘记HTML编码(< / code>到& lt; 等),否则它将全部在第一个角度支架分开。

I'm trying to display emails with IMAP. When the email is text though, the newlines \n don't display properly. I'd rather not convert them to breaks < br /> because if the user wanted to reply to that email, it would now be in HTML instead of plain text. Is there perhaps a javascript function that could display it as a line break without changing the code?

解决方案

How about HTML/CSS? If you put your text inside a <pre> tag, it will show all newlines exactly as they were. Alternatively, you can achieve the same effect by applying the CSS style white-space:pre to any element.

Don't forget to HTMLencode it still (< to &lt; etc.), otherwise it will all break apart at the first angle bracket.

这篇关于你可以把换行符显示为中断&lt; br /&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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