单选按钮无障碍性(508合规)

5

如果我想使用“是/否”单选按钮来提问,我需要如何标记代码,以便屏幕阅读器在选择单选按钮时读取与“是/否”相关联的问题,而不仅仅是读取“Yes”和“No”标签?

<span>Did you understand this? (choose one) </span>
<label>
<input type="radio" id="yes_no" name="yes_no" value="Yes" />
Yes
</label>
<label>
<input type="radio" id="yes_no" name="yes_no" value="No" />
No
</label>

谢谢

3个回答

10

对于这种类型的表单元素,我使用以下代码:

<fieldset>
  <legend>Did you understand the question?</legend>
  <input type="radio" name="yes_no" id="yes">
  <label for="yes">Yes</label>
  <input type="radio" name="yes_no" id="no">
  <label for="no">No</label>
</fieldset>

请注意,在页面上所有ID值都应该是唯一的。如果您有一个需要共享描述符的元素,可以将其添加为类。

我还使用Fieldsets来为单选按钮添加明显的边界。

并且一定要指定


这正是我所需要的。 :D - Jim Ford
1
tabindex怎么办?你肯定会因此被ADA扣分。 - Phillip Holmes

2
<fieldset>
<legend><span>Did you understand this? (choose one) </span></legend>
<label>
<input type="radio" id="yes_no" name="yes_no" value="Yes" />
Yes
</label>
<label>
<input type="radio" id="yes_no" name="yes_no" value="No" />
No
</label>
</fieldset>

-1
使用 content 属性(如果它可用)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接