单选按钮可访问性(符合508标准)

Jai*_*cia 5 html accessibility section508

如果我想要一个带有"是/否"单选按钮的问题.我如何标记代码,以便屏幕阅读器读取与"是/否"选项相关的问题,而不是仅在选择单选按钮时读取"是"和"否"标签?

<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>
Run Code Online (Sandbox Code Playgroud)

谢谢

gru*_*led 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>
Run Code Online (Sandbox Code Playgroud)

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

我还使用Fieldsets为无线电选择添加一个明确的边界.

并确保指定标签的for ="id_value"属性.这会将标签与所需的单选按钮相关联.