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 |
浏览器兼容性
加载中…