aria-describedby 包含 div 而不是输入 - 可用吗?

aria-describedby on containing div instead of input - usable?

是否可以将 aria-describedby 放在包含输入的 div 上?

(而不是仅仅把它放在输入上。)

<p id="description">Description of input</p>

<div aria-describedby="description">
  <input type="text">
  <input type="text">
  <input type="text">
</div>

更新:

正如 Steve Faulkner 在下面所说,这可以通过在 div 上放置一个 role="group" 和一个 aria-labelledby 属性来完成。这实现了与 fieldset-legend 基本相同的效果。优点是:您可以将 "legend" 与 "fieldset" 分开。如果没有必要,最好坚持使用常规的 fieldset-legend。

在下面的 link 中解释了此技术:

Using grouping roles to identify related form controls

如果您想同时使用描述和标签(使用 role="application" ),请参阅下面的 link:

Using the aria-describedby attribute

这不会按预期工作,原因如下:

  1. div 元素通常不会在可访问性树中公开,因此不会将其存在(及其关联的描述字符串)传达给用户
  2. 参考practical support for aria-describedby