---
id: 587d778b367417b2b2512aa7
title: 将单选按钮包裹在 fieldset 元素中以获得更好的可访问性
challengeType: 0
videoUrl: 'https://scrimba.com/c/cVJVefw'
forumTopicId: 301030
dashedName: wrap-radio-buttons-in-a-fieldset-element-for-better-accessibility
---
# --description--
下一个表单主题涵盖单选按钮的可访问性。 在上一个挑战中,每个单选按钮都有一个包含 `for` 属性的 `label` 标签,这些属性值指向相关选项的 `id`。 然而单选按钮通常成组出现,而且用户必须选择其中一项。
`fieldset` 标签包裹整组单选按钮,实现这个功能。 我们可以使用 `fieldset` 标签将单选按钮组包含在里面,通常还会使用 `legend` 标签来为单选按钮组提供文字说明。 屏幕阅读器也可以朗读这些文字。
当选项的含义很明确时,如“性别选择”,`fieldset` 与 `legend` 标签可以省略。 这时,使用包含 `for` 属性的 `label` 标签就足够了。
举个例子:
```html