我有一个带有文本区域的表单,我想在输出内容时保留用户输入的换行符。
例如,如果我在 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.
我想要相同的输出但不:
Here is a sentence. Here is another. here is one more. This is a new paragraph. Here is a new sentence. Here is another.
如何保留换行符?
最佳答案
一般只需要添加
white-space: pre-line;
将空格修剪为单个空格或white-space: pre-wrap;
所有空白保留
到元素的样式 (CSS),您希望在其中呈现带有换行符的文本。
关于html - 保留文本区域中的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30593103/