为什么 WHATWG 不允许 HTML 4 和 HTML5 中的嵌套表单? [英] Why WHATWG disallows nested forms in HTML 4 and HTML5?

查看:20
本文介绍了为什么 WHATWG 不允许 HTML 4 和 HTML5 中的嵌套表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 WHATWG 不允许 HTML 4 和 HTML5 中的嵌套表单?

Why does the WHATWG disallow nested forms in HTML 4 and HTML5?

编辑:问题最初在 如何克服 HTML 表单嵌套限制中描述?

简而言之作者说:您正在制作一个博客应用程序,并且您有一个表单,其中包含一些用于创建新帖子的字段和一个带有操作"的工具栏.如保存"删除"、取消"...唯一的问题是按下删除"将提交服务器上的所有表单字段,即使此操作唯一需要的是带有 post-id 的隐藏输入.

In short author says: You are making a blog app and you have a form with some fields for creating a new post and a toolbar with "actions" like "Save", "Delete", "Cancel"... The only problem is that pressing "Delete", will submit ALL the form fields on the server even though the only thing needed for this action is a Hidden input with the post-id.

因此,这是一个关于表单中的多个按钮提交不同的输入字段集(如多个表单可能允许)的优雅解决方案(没有 JavaScript)的问题strong> 从用户角度将 UI 排列成单个实体(表单").

So, it is a question about an elegant solution (without JavaScript) for several buttons in a form to submit different sets of input fields (like several forms could allow) and to line up UI into single entity ("form") from user perspective.

对该讨论的评论:几乎不可能将元素的屏幕位置与其在文档中的位置完全分开.

Comment from that discussion: it's almost impossible to completely separate the elements' screen position from their position in the document.

编辑:我发现了有趣的笔记 https://web.archive.org/web/20170420110433/http://anderwald.info/internet/nesting-form-tags-in-xhtml/ - (X)HTML 不允许嵌套表单,例如form >"形式",但允许形式"字段集表单",W3 验证器说它是有效的,但浏览器存在这种嵌套的错误.

EDIT: I found interesting note https://web.archive.org/web/20170420110433/http://anderwald.info/internet/nesting-form-tags-in-xhtml/ - that (X)HTML disallows nesting forms like "form > form", but allows "form > fieldset > form", W3 validator says it is valid, but browsers have bugs with such nesting.

推荐答案

就 HTML5(规范草案)而言,情况并不像 David Dorward 所说的那么明确.事实是,如果不添加在标记中分隔表单的新方法,就无法以向后兼容的方式在 text/html 序列化中指定嵌套表单.

As far as HTML5 (the draft spec) goes, the situation is not nearly as clear cut as David Dorward suggests. What is true, is that there's no way that nested forms can be specified in the text/html serialization in a backward-compatible way without adding a new way of delimiting forms in markup.

另一方面,在 application/xhtml+xml 序列化中,不仅可以标记嵌套表单,而且 HTML5 也有一些长度( http://dev.w3.org/html5/spec/forms.html#form-owner ) 来指定应该发生什么案件.此外,对最新版本的 FireFox、Opera、Chrome 和 Safari 以及 IE9 平台预览版的快速测试表明,它们都符合 HTML5 的规定.

On the other hand, in the application/xhtml+xml serialization, it's not only possible to markup nested forms, but HTML5 goes to some lengths ( http://dev.w3.org/html5/spec/forms.html#form-owner ) to specify what should happen in this case. Further, a quick test around the latest versions of FireFox, Opera, Chrome, and Safari, plus IE9 platform preview shows that they all do what HTML5 specifies.

因此,它可能在 HTML5 内容模型中有效,但事实并非如此.什么决定什么有效,什么无效很大程度上取决于用例.到目前为止,还没有人向 WHATWG 或 W3C HTML WG 提供足够引人注目的用例,使嵌套表单成为有效 HTML5 的一部分.

So, it could have been valid in the HTML5 content model, but it isn't. What determines what is valid and what isn't rests largely on use-cases. So far, no one has provided a sufficiently compelling use case to WHATWG or the W3C HTML WG for making nested forms a part of valid HTML5.

这篇关于为什么 WHATWG 不允许 HTML 4 和 HTML5 中的嵌套表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆