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。