在textarea中保留换行符 [英] Preserve line breaks in textarea

查看:765
本文介绍了在textarea中保留换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,如果我在textarea中写入:如果我在textarea中写入:


这是一个句子。这是另一个。这里还有一个。



这是一个新的段落。这是一个新的句子。


我需要相同的输出,不是


这是一个句子。这是另一个。这里还有一个。这是一个新的
段落。这是一个新的句子。这是另一个。


我如何保留换行符?

解决方案

通常您只需添加


  • white-space: pre-line; 将空格修剪为单个空格


  • space:pre-wrap; 保留所有空格




添加到元素的样式(CSS) ,您希望您的文本以换行符呈现。


I have a form with a textarea and I want to preserve line breaks entered by the user when outputting the content.

For exemple, if I write in textarea :

Here is a sentence. Here is another. here is one more.

This is a new paragraph. Here is a new sentence. Here is another.

I want the same output and not :

Here is a sentence. Here is another. here is one more. This is a new paragraph. Here is a new sentence. Here is another.

How could I preserve line breaks?

解决方案

Generally you just need to add

  • white-space: pre-line; whitespace trimmed to single whitespace or

  • white-space: pre-wrap; all whitespace preserved

to the element's style (CSS), where you want your text rendered with line-breaks.

这篇关于在textarea中保留换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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