如何在textarea中显示换行符? [英] How to show newlines from textarea in a table?

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

问题描述

在一个表单中,我有一个textarea,在那里明显地输入文本。当输入完成后,内容被提交到服务器并存储在数据库中...

当我显示用户在表格中输入的内容时,换行符不可见。当我检查源代码时,换行符在那里,但在表格中,换行符不起作用......

是否有可能在该表格中显示换行符?
我知道,可能是一个非常愚蠢的问题,但我不会亲,当涉及到像HTML和CSS的东西......



任何帮助是真的赞赏!

解决方案

\\\
不会在HTML中呈现为新行。您必须使用< br /> 才能达到此效果。

使用替换字符串替换所有'\ n'个字符转换为'< br /> '



如果 ,您正在使用像 C# 这样的服务器端语言,那么您可以执行此操作。

 私人字符串PutLineBreaks(字符串strData)
{
字符串strReplaced = string.Empty;

Regex r = new Regex(/ \\\
/ g);

strReplaced = r.Replace(strData,< br />);

返回str替换;
}


In a form I have a textarea where obviously text is entered. When the input is finished the content gets submitted to the server and is being stored in a database...

When I display the input the user made within a table, the newlines are not visible. When I inspect the source the newlines are there, but within a table the newlines do not work...

Is there any possibility of displaying the linebreaks within that table? I know, probably a really silly question but I'm not to pro when it comes to things like html and css...

Any help is really appreciated!

解决方案

\n won't be rendered as a new line in HTML. You have to use a <br/> to achieve this effect.

Use a string replace to replace all '\n' characters to '<br/>'

If you are using a server side language like C# you can do this

private string PutLineBreaks(string strData)
{
    string strReplaced = string.Empty;

    Regex r = new Regex("/\n/g");

    strReplaced = r.Replace(strData, "<br/>");

    return strReplaced;
}

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

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