XPathResult:snapshotLength 屬性
注意:此功能在 Web Workers 中可用。
XPathResult 介面的只讀 snapshotLength 屬性表示結果快照中的節點數量。
值
一個表示結果快照中節點數量的整數值。
異常
TYPE_ERR
如果 XPathResult.resultType 不是 UNORDERED_NODE_SNAPSHOT_TYPE 或 ORDERED_NODE_SNAPSHOT_TYPE,則會丟擲型別為 TYPE_ERR 的 DOMException。
示例
以下示例顯示了 snapshotLength 屬性的用法。
HTML
html
<div>XPath example</div>
<div>Number of matched nodes: <output></output></div>
JavaScript
js
const xpath = "//div";
const result = document.evaluate(
xpath,
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null,
);
document.querySelector("output").textContent = result.snapshotLength;
結果
規範
| 規範 |
|---|
| DOM # dom-xpathresult-snapshotlength |
瀏覽器相容性
載入中…