Element: ariaFlowToElements 属性
Element
接口的 ariaFlowToElements
属性是一个数组,其中包含提供内容备用阅读顺序的元素(一个或多个),用户可以自行决定是否覆盖通用的默认阅读顺序。如果只提供了一个元素,则该元素是阅读顺序中的下一个元素。如果提供了多个元素,那么每个元素都代表一个用户可以选择的可能路径。
有关属性和元素如何使用的更多信息,请参阅 aria-flowto
主题。
值
HTMLElement
的子类数组。
读取时,返回的数组是静态的且只读的。写入时,将复制分配的数组:之后对数组的更改不会影响属性的值。
描述
该属性是使用 aria-flowto
属性设置备用阅读顺序的灵活替代方案。与 aria-flowto
不同,分配给此属性的元素不必具有 id
属性。
当定义了 ariaFlowToElements
属性时,该属性将反映元素的 aria-flowto
属性,但仅限于列出的、匹配有效作用域内元素的引用 id
值。如果设置了该属性,则相应的属性将被清除。有关反映的元素引用和作用域的更多信息,请参阅Reflected attributes指南中的 Reflected element references。
示例
获取流向元素
此示例演示了三个元素 section1
、section2
、section3
的正常流程顺序,以及一个从 section1
跳转到 section3
再返回的备用顺序。请注意,除非您运行了辅助功能工具,否则此示例仅作说明之用:我们实际上不会遵循此备用路径。
HTML
HTML 定义了三个 <div>
元素,它们定义了具有 "section"
类和 id
值(section1
、section2
和 section3
)的节。每个节都有一个由其顺序定义的正常流程,从 section1
开始,到 section3
结束。在第 1 节和第 3 节中使用 aria-flowto
属性定义了一个备用流程。
<div id="section1" class="section" aria-flowto="section3">
<h2>Section 1</h2>
<p>First section in normal flow. Section 3 is alternate flow.</p>
<a href="#section2">Jump to Section 2 (normal flow)</a>
</div>
<div id="section2" class="section">
<h2>Section 2</h2>
<p>Second section in normal flow.</p>
<a href="#section3">Jump to Section 3 (normal flow)</a>
</div>
<div id="section3" class="section" aria-flowto="section1">
<h2>Section 3</h2>
<p>
Third section in normal flow (end of flow). Section 1 is alternate flow.
</p>
</div>
JavaScript
代码首先检查 ariaFlowToElements
是否受支持,如果支持,则记录其值。然后,它遍历这些节,记录节的 id
、aria-flowto
属性值以及 ariaFlowToElements
属性值。
// Feature test for ariaFlowToElements
if ("ariaFlowToElements" in Element.prototype) {
const sections = document.querySelectorAll(".section");
sections.forEach((sectionDivElement) => {
log(`${sectionDivElement.id}`);
log(` aria-flowto: ${sectionDivElement.getAttribute("aria-flowto")}`);
log(" ariaFlowToElements:");
// Get the ids of each of the elements in the array
sectionDivElement.ariaFlowToElements?.forEach((elem) => {
log(` id: ${elem.id}`);
});
});
} else {
log("element.ariaFlowToElements: not supported by browser");
}
结果
下面的日志显示了每个节(由 id
标识)以及辅助功能工具可能选择的相应流向元素 id。我们在此指出,属性和属性识别的是相同的流向元素。
规范
规范 |
---|
无障碍富互联网应用程序 (WAI-ARIA) # dom-ariamixin-ariaflowtoelements |
浏览器兼容性
加载中…
另见
aria-flowto
属性ElementInternals.ariaFlowToElements
- Attribute reflection 指南中的Reflected element references。