VoiceOver 选中某个radio后 重读了整个页面

如果在 VoiceOver 选中某个 radio 按钮后,屏幕阅读器重读了整个页面,可以检查下面的一些设置。

1. aria-live 设置范围过大

aria-live="polite" 或 aria-live="assertive" 可能被设置在一个包含大量内容的元素(如 <body>、<main>),导致 VoiceOver 在 radio 选中后重新朗读整个页面。

检查代码,确保 aria-live 仅应用于需要通知的部分,而不是整个页面。

解决方案:限制 aria-live 作用范围,避免全局影响:

<div aria-live="polite" id="status-message">选择一个选项</div>

2. aria-atomic="true" 导致整个区域被朗读

如果 aria-atomic="true",即使 radio 选项的内容仅部分变化,VoiceOver 也可能朗读整个 aria-live 区域。

解决方案:使用 aria-atomic="false",让屏幕阅读器只读变化的部分:

<div aria-live="polite" aria-atomic="false">选中:选项 A</div>

3. fieldset 或 legend 影响朗读行为

fieldset 和 legend 可能会让 VoiceOver 在选中 radio 时,额外朗读整个 fieldset 内的内容。

解决方案:确保 legend 仅用于分组,并适当优化 aria-labelledby:

<fieldset>
  <legend id="group-label">请选择一个选项</legend>
  <input type="radio" id="option1" name="group" aria-labelledby="group-label option1-label">
  <label id="option1-label" for="option1">选项 1</label>

  <input type="radio" id="option2" name="group" aria-labelledby="group-label option2-label">
  <label id="option2-label" for="option2">选项 2</label>
</fieldset>

4. onchange 事件引发页面重新渲染

如果 radio 选项 onchange 事件触发了整个 div 或 form 重新渲染,可能会导致 VoiceOver 朗读整个页面。

解决方案:仅更新 aria-live 指定的内容,而非整个表单:

<script>
  function updateStatus(value) {
    document.getElementById('status-message').innerText = "已选:" + value;
  }
</script>

<form>
  <fieldset>
    <legend>请选择颜色:</legend>
    <input type="radio" id="red" name="color" value="红色" onchange="updateStatus('红色')">
    <label for="red">红色</label>

    <input type="radio" id="blue" name="color" value="蓝色" onchange="updateStatus('蓝色')">
    <label for="blue">蓝色</label>
  </fieldset>
  <div aria-live="polite" id="status-message">请选择一个颜色</div>
</form>

你可以尝试优化代码,并使用 VoiceOver 进行测试,看是否仍然存在问题。

评论 添加
暂无评论,来聊两句?