html - 对字段集和表单标签嵌套的一点帮助

标签 html forms

我目前正在使用 JSP 编写一个 Java EE 网络应用程序,我有一个关于 HTML 标签的问题。

我使用字段集在主页上正确构建我的表单,发现自己感到困惑,想知道以下是否合法:

<fieldset id="FieldMain">
    <form method="post" action="servletA">
        <input name="a" type="text" />
        <fieldset id="FieldA">
            <input name="b" type="text" />
            <input name="c" type="text" />
            <input name="d" type="submit" value="Go for A" />
        </fieldset>
    </form>
    <form method="post" action="servletB">
        <fieldset id="FieldB">
            <input name="e" type="text" />
            <input name="f" type="text" />
            <input name="g" type="submit" value="Go for B" />
        </fieldset
    </form>
</fieldset>

期望的结果是,当单击“Go for A”按钮时,它会考虑字段 a、b 和 c(a 在字段集 fieldA 之外,但在表单 A 标记内),同时单击“go for B”采用字段 e 和 f。

换句话说,如果我使用字段集,我可以在一个字段集标签中包含多个表单吗?我是否可以在任何字段集标签之外添加一些字段,只要它在表单标签中即可?

谢谢 :-)

最佳答案

这是合法的,但并不是要这样做

The FIELDSET element allows authors to group thematically related controls and labels. Grouping controls makes it easier for users to understand their purpose while simultaneously facilitating tabbing navigation for visual user agents and speech navigation for speech-oriented user agents. The proper use of this element makes documents more accessible.

来源:http://www.w3.org/TR/html4/interact/forms.html#h-17.10

As far as I remember form past discussions: it's legal according to the letter of the standard and the DTD also makes it valid where a block element is valid. Now as to intend, that's harder to determine, it feels to me to be intended to be used in forms only. I don't know why it got the far wider scope.

Also note that -despite the CSS standard not stating it should- a fieldset creates a new stacking context (logical if you think about it and the default way it's rendered, but not mentioned in the standard AFAIK).

IMHO extensive use of it outside forms and/or reliance on the new stacking context are dangerous if you want future proof code.

来源:http://www.webmasterworld.com/html/3915579.htm

关于html - 对字段集和表单标签嵌套的一点帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14159540/

相关文章:

javascript - Bootstrap 文本对齐 : Empty input left - Filled input right

javascript - Magento 表单验证,表单不提交有效字段

php - 如何设计静态/动态测量应用程序?

javascript - 在 Javascript 中获取查询字符串数组值

jquery - 使用 Jquery 删除文本

jquery - 选中复选框时更改标签

html - 为什么 <p> 高度为 0% 时仍然可见

html - 关于 Bootstrap 中可折叠导航栏的问题

forms - 找不到模块 '@angular/forms'

通过返回 false 和通过类选择的表单问题的 JavaScript 验证