为什么我们需要一个fieldset标签? [英] Why do we need a fieldset tag?

查看:104
本文介绍了为什么我们需要一个fieldset标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们需要一个<fieldset>标签?无论它服务于什么目的,都可能是form标签的子集.

Why do we need a <fieldset> tag? Whatever purpose it serves is probably a subset of the form tag.

我在W3Schools上查找了一些信息,说:

I looked up some info on W3Schools, which says:

  • <fieldset>标记用于将表单中的相关元素分组.
  • <fieldset>标记在相关元素周围绘制了一个框.
  • The <fieldset> tag is used to group related elements in a form.
  • The <fieldset> tag draws a box around the related elements.

对于那些将为什么它存在于规范中"误认为它做什么"的人的更多解释. 我认为绘图部分无关紧要,而且我不明白为什么我们只需要一个特殊的标签就可以将表单中的一些相关元素分组.

More explanation for those who are mistaking "why it exists in specification" for "what it does". I think the drawing part is irrelevant, and I don't see why we need a special tag just to group some related elements in a form.

推荐答案

最明显的实际示例是:

<fieldset>
  <legend>Colour</legend>

  <input type="radio" name="colour" value="red" id="colour_red">
  <label for="colour_red">Red</label>

  <input type="radio" name="colour" value="green" id="colour_green">
  <label for="colour_green">Green</label>

  <input type="radio" name="colour" value="blue" id="colour_blue">
  <label for="colour_blue">Blue</label>

</fieldset>

这将使每个单选按钮都具有标签,同时还为整个组提供标签.这在使用辅助技术(例如屏幕阅读器)的情况下尤其重要,在这种情况下,视觉表示不能暗示控件及其图例的关联.

This allows each radio button to be labeled while also providing a label for the group as a whole. This is especially important where assistive technology (such as a screen reader) is being used where the association of the controls and their legend cannot be implied by visual presentation.

这篇关于为什么我们需要一个fieldset标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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