使用fieldset标签有什么优点?

发布于 2024-11-17 17:07:44 字数 89 浏览 3 评论 0原文

使用

标签有哪些优点?

我实在不明白它是做什么用的。

What are the advantages of using the <fieldset> tag?

I don't really get what it is used for.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

泼猴你往哪里跑 2024-11-24 17:07:44

表单通常分为不同的字段集。

字段集标签允许您对字段集进行逻辑分组,以便您的表单更具描述性。

您还会注意到,您可以使用字段集来设计表单的样式并显示字段之间的逻辑关联。

就像您在“真实”世界中找到的形式一样。

使用字段集的“优点”是它们允许您以最可用的语义方式标记数据(在本例中为表单)。请考虑将字段放在字段集中比将字段放在 div 中更具描述性。 div 不会告诉您字段之间的关系,而字段集会告诉您存在某种关系。

这与许多新的 HTML5 标记集的原理类似。例如,与模糊的

相比,

可以告诉您更多有关其中数据含义的信息。

Forms are often broken up into various sets of fields.

The fieldset tag allows you to logically group sets of fields in order that your forms be more descriptive.

You'll also note that you can use the fieldset to style your forms and display those logical associations between fields.

Just like forms you find in the "real" world.

The "advantages" of using a fieldset are that they allow you to mark up your data (in this case a form) in the most semantic way available. Consider that placing your fields in a fieldset is more descriptive than placing your fields in a div. The div tells you nothing about the relationship between the fields, a fieldset tells you there is a relationship.

It's a similar principle to many of the new HTML5 tagsets. <footer> for example tells you more about the meaning of the data inside it compared to an ambiguous <div>.

悟红尘 2024-11-24 17:07:44

如果您查看面向开发人员的 HTML5 规范

http://developers.whatwg.org/forms.html#the-fieldset-element

fieldset 元素表示一个集合
可选分组的表单控件
使用通用名称。

(如果您点击链接,会有更多信息)

legend 元素,它可以让你轻松地做到这一点,如果不使用 fieldset/legend 很难重新创建:

<图片src="https://i.sstatic.net/wQ8s2.png" alt="">

If you take a look at the HTML5 spec for Developers:

http://developers.whatwg.org/forms.html#the-fieldset-element

The fieldset element represents a set
of form controls optionally grouped
under a common name.

(there's a lot more information if you follow the link)

Combined with the legend element, it allows you to easily do this, which is difficult to recreate without using fieldset/legend:

锦爱 2024-11-24 17:07:44

它允许您对一组相关字段进行分组并为它们提供图例。

<fieldset>
    <legend>Gender</legend>
    <input type="radio" name="gender" id="male" value="male">
    <label for="male">Male</label>
    <input type="radio" name="gender" id="female" value="female">
    <label for="female">Female</label>
<fieldset>

<fieldset>
    <legend>Address</legend>

    <label for="line1">Line 1</label>
    <input name="address1" id="line1">

    <label for="line2">Line 2</label>
    <input name="address2" id="line2">

    <label for="town">Town</label>
    <input name="town" id="town">

    <label for="country">country/label>
    <input name="country" id="country">
</fieldset>

It allows you to group a set of related fields and give them a legend.

<fieldset>
    <legend>Gender</legend>
    <input type="radio" name="gender" id="male" value="male">
    <label for="male">Male</label>
    <input type="radio" name="gender" id="female" value="female">
    <label for="female">Female</label>
<fieldset>

<fieldset>
    <legend>Address</legend>

    <label for="line1">Line 1</label>
    <input name="address1" id="line1">

    <label for="line2">Line 2</label>
    <input name="address2" id="line2">

    <label for="town">Town</label>
    <input name="town" id="town">

    <label for="country">country/label>
    <input name="country" id="country">
</fieldset>
活泼老夫 2024-11-24 17:07:44

你将东西与它组合在一起。如果您需要通过 CSS 或 JavaScript 访问其中的内容,并且不想经历为所有内容分配 ID 的麻烦,那么这会很有用。

而且,传说看起来也不错。

You group stuff together with it. Which is useful if you need to access things in it for CSS or JavaScript, and don't want to go through the hassle of assigning ID's to everything.

Also, the legend looks pretty good.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文