是<输入>吗?没有
就形成良好?

发布于 2024-09-10 20:33:06 字数 185 浏览 6 评论 0原文

拥有 而不使用

是否有效?

有一个标记页面中某些字段的过程,只是发现一个带有输入字段的页面没有按照我的预期进行标记。
我花了一段时间才发现,获取表单元素然后获取字段的过程是导致这些元素丢失的原因,因为没有表单。

Is it valid to have <input> without it being in a <form>?

Have a process for marking up some fields in pages and just found a page with input fields that where not being marked up as I expected.
It's taken me a while but worked out that the process of getting the form elements then getting the fields is what caused these to be missed because there is no form.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

禾厶谷欠 2024-09-17 20:33:06

没有

似乎有效,是的(至少对于 html 4.01,请查看 17.2.1 末尾附近):

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

<input> without a <form> appears valid, yes (at least for html 4.01, look near the end of 17.2.1):

The elements used to create controls
generally appear inside a FORM
element, but may also appear outside
of a FORM element declaration when
they are used to build user
interfaces. This is discussed in the
section on intrinsic events. Note that
controls outside a form cannot be
successful controls.

剧终人散尽 2024-09-17 20:33:06

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

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

I checked the following with the W3C validator and it confirms this is valid.

<!DOCTYPE html>
<html>
<head>
  <title>test</title>
</head>
<body>
  <input type='text' />
</body>
</html>
爱的那么颓废 2024-09-17 20:33:06

参考更新的规范:

HTML 5.2 - W3C 建议(2017 年 12 月 14 日)

表单关联元素可以与

元素有关系,该元素称为元素的表单所有者。如果表单关联元素未与 元素关联,则称其表单所有者为 null。

Reference to a more up-to-date specification:

HTML 5.2 - W3C Recommendation (14 December 2017)

A form-associated element can have a relationship with a <form> element, which is called the element’s form owner. If a form-associated element is not associated with a <form> element, its form owner is said to be null.

桃扇骨 2024-09-17 20:33:06

根据 MDN,这是可能的:

请注意,始终可以在元素外部使用表单小部件,但如果这样做,该表单小部件与任何表单都无关。此类小部件可以在表单之外使用,但是您应该对此类小部件有一个特殊的计划,因为它们本身不会执行任何操作。您必须使用 JavaScript 自定义它们的行为。

HTML5 在 HTML 表单元素上引入了 form 属性。它应该允许您显式地将元素与表单绑定,即使它没有包含在表单标记中。不幸的是,目前该功能跨浏览器的实现还不够好,无法依赖它。

According to MDN it is possible:

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.

梦年海沫深 2024-09-17 20:33:06

我知道这个问题已经很老了,但是,我已经成功构建了许多没有表单标签的复杂数据输入页面。尽管许多人不认为它是“标准”,但使用没有

的输入并不是不合适的。在我的项目中,我需要完全控制页面的行为方式,而默认的表单行为却妨碍了我。能够执行页面和字段级别的验证(使用 JS )并通过 Ajax 调用等“提交”数据……事实上,这是我现在最喜欢的方式。

需要大量 JS,但这并不困难,并且很容易作为可重用代码完成。

还有其他情况,我不使用带有输入的表单,例如登录页面。

希望这个见证对某人有所帮助。

I know this question is quite old, however, I have successfully built many complex data entry pages without form tags. Although it isn't considered "standard" by many, it is NOT inappropriate to use inputs without a <form>. My projects were instances where I needed complete control over how the page behaved and the default form behavior was getting in the way. Was able to perform page and field level validation ( using JS ) and "submitted" the data with Ajax calls etc...in fact, this is my preferred way these days.

Lots of JS is required, but its not that difficult and is easily done as reusable code.

There are also other instances where I def do NOT use forms with inputs such as Login Pages.

Hope this testimonial helps someone.

压抑⊿情绪 2024-09-17 20:33:06

在我看来,我们可以在表单之外使用输入,甚至可以将数据发送到服务器而不将输入放入表单中,但是为了搜索引擎优化和网站可读性(对于视障人士)(与某些网站的原因相同)
HTML5 中的语义内容标签(例如节、页脚、页眉之类的),我们必须在表单标签中使用输入。确保我们使用的代码可供所有人(包括视障人士)使用非常重要,因为它是不仅仅是网站,它还为每个人提供获取信息的机会。

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.

囚你心 2024-09-17 20:33:06

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

Yes, you can have a valid input without a form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文