在另一个 html 表单中包含一个 html 表单是否有效? [英] Is it valid to have a html form inside another html form?

查看:32
本文介绍了在另一个 html 表单中包含一个 html 表单是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有以下内容的 html 是否有效:

Is it valid html to have the following:

<form action="a">
    <input.../>
    <form action="b">
        <input.../>
        <input.../>
        <input.../>
    </form>
    <input.../>
</form>

因此,当您提交b"时,您只能获得内部表单中的字段.当您提交a"时,您将获得所有字段减去b"中的字段.

So when you submit "b" you only get the fields within the inner form. When you submit "a" you get all fields minus those within "b".

如果不可能,有什么解决方法可以解决这种情况?

If it isn't possible, what workarounds for this situation are available?

推荐答案

A.它不是有效的 HTML 或 XHTML

在官方 W3C XHTML 规范的 B 节元素禁止"中,声明:

In the official W3C XHTML specification, Section B. "Element Prohibitions", states that:

"form must not contain other form elements."

http://www.w3.org/TR/xhtml1/#prohibitions

对于旧的 HTML 3.2 规范,FORMS 元素部分指出:

As for the older HTML 3.2 spec, the section on the FORMS element states that:

"每个表单都必须包含在一个表单元素.可以有几个单个文档中的表单,但FORM 元素不能嵌套."

"Every form must be enclosed within a FORM element. There can be several forms in a single document, but the FORM element can't be nested."

B.解决方法

有一些使用 JavaScript 的解决方法,无需嵌套表单标签.

There are workarounds using JavaScript without needing to nest form tags.

如何创建嵌套表单."(尽管标题不是嵌套表单标签,而是一种 JavaScript 解决方法).

"How to create a nested form." (despite title this is not nested form tags, but a JavaScript workaround).

此 StackOverflow 问题的答案

注意: 尽管可以通过脚本操纵 DOM 来欺骗 W3C 验证器来传递页面,但它仍然不是合法的 HTML.使用这种方法的问题是现在不能保证跨浏览器的代码行为.(因为它不是标准的)

这篇关于在另一个 html 表单中包含一个 html 表单是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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