Html 为什么 textarea 不是输入[type="textarea"]?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5637326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why isn't textarea an input[type="textarea"]?
提问by Diogo Cardoso
Why is there an element <textarea>
instead of <input type="textarea">
?
为什么有一个元素<textarea>
而不是<input type="textarea">
?
回答by Marcel
Maybe this is going a bit too far back but…
也许这有点过时了,但是......
Also, I'd like to suggest that multiline text fields have a different type (e.g. “textarea") than single-line fields ("text"), as they really are different types of things, and imply different issues (semantics) for client-side handling.
另外,我想建议多行文本字段具有与单行字段(“文本”)不同的类型(例如“textarea”),因为它们确实是不同类型的事物,并且暗示不同的问题(语义)客户端处理。
回答by Guillaume Esquevin
So that its value can easily contain quotes and <> characters and respect whitespace and newlines.
这样它的值可以很容易地包含引号和 <> 字符并尊重空格和换行符。
The following HTML code successfully pass the w3c validatorand displays <,> and & without the need to encode them. It also respects the white spaces.
以下 HTML 代码成功通过了w3c 验证器并显示 <、> 和 &,而无需对它们进行编码。它还尊重空白。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Yes I can</title>
</head>
<body>
<textarea name="test">
I can put < and > and & signs in
my textarea without any problems.
</textarea>
</body>
</html>
回答by Mark Cidade
A textarea
can contain multiple lines of text, so one wouldn't be able to pre-populate it using a value
attribute.
Atextarea
可以包含多行文本,因此无法使用value
属性预先填充它。
Similarly, the select
element needs to be its own element to accommodate option
sub-elements.
同样,select
元素需要是它自己的元素以容纳option
子元素。
回答by Izkata
It was a limitation of the technology at the time it was created. My answer copied over from Programmers.SE:
这是技术在创建时的限制。 我的答案是从 Programmers.SE 复制过来的:
From one of the original HTML drafts:
来自原始HTML 草稿之一:
NOTE: In the initial design for forms, multi-line text fields were supported by the Input element with TYPE=TEXT. Unfortunately, this causes problems for fields with long text values. SGML's default (Reference Quantity Set) limits the length of attribute literals to only 240 characters. The HTML 2.0 SGML declaration increases the limit to 1024 characters.
注意:在表单的初始设计中,带有 TYPE=TEXT 的 Input 元素支持多行文本字段。不幸的是,这会导致具有长文本值的字段出现问题。SGML 的默认值(参考数量集)将属性文字的长度限制为仅 240 个字符。HTML 2.0 SGML 声明将限制增加到 1024 个字符。
回答by Chas Latch
I realize this is an older post, but thought this might be helpful to anyone wondering the same question:
我意识到这是一篇较旧的帖子,但认为这可能对任何想知道相同问题的人有所帮助:
While the previous answers are no doubt valid, there is a more simple reason for the distinction between textarea and input.
虽然前面的答案无疑是有效的,但区分 textarea 和 input 的原因更简单。
As mentioned previously, HTML is used to describe and give as much semantic structure to web content as possible, including input forms. A textarea maybe used for input, however a textarea can also be marked as read only via the readonly attribute. The existence of such an attribute would not make any sense for an inputtype, and thus the distinction.
如前所述,HTML 用于描述和赋予 Web 内容尽可能多的语义结构,包括输入表单。textarea可用于输入,但是 textarea 也可以通过 readonly 属性标记为只读。这种属性的存在对输入类型没有任何意义,因此区分。