为什么输入标签不能直接在表单标签中使用? [英] Why is an input tag not allowed directly within a form tag?
本文介绍了为什么输入标签不能直接在表单标签中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚在 http://w3fools.com/#html_forms 上阅读以下内容:
非块级元素(例如
< input>
)无法直接在< form>
标签直到HTML5。
我从来没有听说过这些内容,我看过的每个基本的HTML教程似乎都将输入标签直接放在表单标签中。所以我的问题有三个部分:
$ ul
$ b
- 根据标准,声明是合法的:在HTML 4.01中,
< form>
指定它可能只包含块元素或< script>
。至于世界上每个浏览器都允许的情况,这没什么。 - 我只能猜测他们认为
< form>
为不是布局标签,他们希望所有内联元素都包含在块元素中。 - 是的,您应该放置
< div>
,< table>
,< p>
< form>
中的表现元素。
I just read the following at http://w3fools.com/#html_forms:
Non-block-level elements (such as
<input>
) are not valid directly inside<form>
tags until HTML5.
I had never heard of anything along these lines, and every basic HTML tutorial I've seen seems to be just fine with putting input tags directly inside a form tag. So my question has three parts:
- Is the above statement legitimate?
- Why is this the case? (Was it simply an oversight, or were the creators of the HTML spec trying to prevent specific problems by creating this rule?)
- What is the recommended way to construct a form with inputs? (Are we just supposed to create a div or a table directly inside the form tag?)
解决方案
It's standards pedantics.
- The statement is legitimate as far as the standard goes: in HTML 4.01, the definition for
<form>
specifies that it may only contain block elements or<script>
. As far as what every browser in the world allows, it's fine. - I can only guess that they consider
<form>
to not be a layout tag at all, and they want all inline elements to be contained inside a block element. - Yes, you're supposed to place a
<div>
,<table>
,<p>
, or some other block presentational element inside the<form>
.
这篇关于为什么输入标签不能直接在表单标签中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文