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

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

问题描述

是否有效的html包含以下内容:

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

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

如果不可能,可以使用哪种解决方法?

解决方案

A。 HTML和XHTML无效 在官方的W3C XHTML规范中,B部分元素禁止指出:

 表单不得包含其他表单元素。 

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



至于较老的 HTML 3.2规范
关于FORMS元素的部分规定:


每个表单必须包含在
FORM元素中,在单个文档中可以有多个
表单,但
FORM元素不能嵌套。


B。 解决方法



使用JavaScript的解决方法无需嵌套表单标签。



如何创建嵌套表单。(尽管title不是嵌套表单标签,而是JavaScript解决方法)。



http://blog.avirtualhome.com/how-to -create-nested-forms /



注意: 虽然可以诱使W3C验证器通过通过脚本操作DOM,它仍然不合法的HTML。使用这种方法的问题是现在不能跨浏览器保证代码的行为。 (因为它不是标准的)


Is it valid html to have the following:

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

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. It is not valid HTML nor XHTML

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

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

"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. The Workaround

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

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

http://blog.avirtualhome.com/how-to-create-nested-forms/

Note: Although one can trick the W3C Validators to pass a page by manipulating the DOM via scripting, it's still not legal HTML. The problem with using such approaches is that the behavior of your code is now not guaranteed across browsers. (since it's not standard)

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

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