是<输入>吗?没有
输入>拥有 而不使用
有一个标记页面中某些字段的过程,只是发现一个带有输入字段的页面没有按照我的预期进行标记。
我花了一段时间才发现,获取表单元素然后获取字段的过程是导致这些元素丢失的原因,因为没有表单。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
没有
<input>
without a<form>
appears valid, yes (at least for html 4.01, look near the end of 17.2.1):我使用 W3C 验证器检查了以下内容,它确认这是有效的。
I checked the following with the W3C validator and it confirms this is valid.
参考更新的规范:
HTML 5.2 - W3C 建议(2017 年 12 月 14 日)
Reference to a more up-to-date specification:
HTML 5.2 - W3C Recommendation (14 December 2017)
根据 MDN,这是可能的:
According to MDN it is possible:
我知道这个问题已经很老了,但是,我已经成功构建了许多没有表单标签的复杂数据输入页面。尽管许多人不认为它是“标准”,但使用没有
需要大量 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.
在我看来,我们可以在表单之外使用输入,甚至可以将数据发送到服务器而不将输入放入表单中,但是为了搜索引擎优化和网站可读性(对于视障人士)(与某些网站的原因相同)
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.
是的,您可以在没有表单的情况下获得有效的输入。
Yes, you can have a valid input without a form.