有<input>而不是<form>是有效的吗?

有一个在页面中标记一些字段的过程,只是发现了一个输入字段的页面,那里没有被标记为我所期望的。 这花了我一段时间,但得出的过程中,得到的形式元素,然后得到的领域是什么导致这些错过,因为没有形式。


当前回答

<input>没有<form>是有效的,是的(至少对于HTML 4.01,看17.2.1的结尾):

用于创建控件的元素 通常出现在表单中 元素,但也可能出现在外部 的FORM元素声明 它们被用来建立用户 接口。这在 内在事件部分。请注意, 窗体之外的控件则不能 成功的控制。

其他回答

根据MDN,这是可能的:

Note that it's always possible to use a form widget outside of a element but if you do so, that form widget has nothing to do with any form. Such widgets can be used outside a form, but then you should have a special plan for such widgets, since they will do nothing on their own. You will have to customize their behavior with JavaScript. HTML5 introduces the form attribute on HTML form elements. It should let you explicitly bind an element with a form even if it is not enclosed within a form tag. Unfortunately, for the time being, the implementation of this feature across browsers is not yet good enough to rely on it.

我用W3C验证器检查了以下内容,并确认这是有效的。

<!DOCTYPE html>
<html>
<head>
  <title>test</title>
</head>
<body>
  <input type='text' />
</body>
</html>

<input>没有<form>是有效的,是的(至少对于HTML 4.01,看17.2.1的结尾):

用于创建控件的元素 通常出现在表单中 元素,但也可能出现在外部 的FORM元素声明 它们被用来建立用户 接口。这在 内在事件部分。请注意, 窗体之外的控件则不能 成功的控制。

in my point of view , we can use input outside the form and even send data to the server without put the input in the form ,but for SEO and website readability(for visually impaired people)(just the same reason for the some semantic content tags in HTML5 , like section ,footer, header something like that ), we have to use input in the form tag.It is important that we ensure the code we use is available to all people including the visually impaired people because it is not just about websites, it is about providing access to information for everyone.

是的,您可以在没有表单的情况下获得有效的输入。