简体   繁体   English

显示输入数据的最佳实践是什么 - textarea 与 p 标签

[英]what is best practice to show typed data - textarea vs p tag

I have a form that users create a profile.我有一个用户创建配置文件的表单。 In the form there is a textarea in which hey put their blurb / description whatever.在表单中有一个文本区域,嘿,在其中放置他们的简介/描述。

Later when I want to show the profile in a view only screen, what is best practice?稍后当我想在仅查看屏幕中显示配置文件时,最佳实践是什么? To use a <p> tag or an html tag?使用<p>标签还是 html 标签?

It appears I lose the paragraphs etc when I display the data in a <p> tag.当我在<p>标签中显示数据时,我似乎丢失了段落等。

If, the best practice is to maybe use a readonly textarea for view purposes, how can one dynamically adjust the rows depending on the length of text?如果最佳实践是使用只读文本区域进行查看,那么如何根据文本长度动态调整行?

Textareas are designed for accepting input from users, not displaying data back to them. Textareas 旨在接受来自用户的输入,而不是向他们显示数据。

You need to process the submitted data before displaying it on the user profile.您需要先处理提交的数据,然后再将其显示在用户配置文件上。 Typically this would involve formatting (like splitting the content on double new lines and then wrapping each part of the result with paragraphs) and implementing protection against XSS attacks.通常,这将涉及格式化(例如将内容拆分为两个新行,然后用段落包装结果的每个部分)并实施针对 XSS 攻击的保护。

For formatting, you might consider using a Markdown engine (similar to what Stackoverflow does).对于格式化,您可以考虑使用 Markdown 引擎(类似于 Stackoverflow 所做的)。

Use the <p> tag.使用<p>标签。 It is ok, but you should modify the contents, before output at least with two functions:没关系,但是你应该修改内容,在输出之前至少有两个功能:

1) htmlentities() - to protect against XSS attacks and print any html symbols as text 1) htmlentities() - 防止 XSS 攻击并将任何 html 符号打印为文本

2) nl2br() - to add <br/> tags (html new line) next to \\n symbols (new line in text format) 2) nl2br() - 在\\n符号(文本格式的新行)旁边添加<br/>标签(html 换行)

You can look at the <pre> tag as well, then you do not need the nl2br() function您也可以查看<pre>标签,然后就不需要nl2br()函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM