Web 接口
XPathEvaluator - 用于编译和求值 XPath 表达式
HTML
源代码:
点击运行 »
<div>XPath 实例</div> <div><div> 的数量:<output></output></div> <script> var xpath = "//div"; var evaluator = new XPathEvaluator(); var expression = evaluator.createExpression("//div"); var result = expression.evaluate(document, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE); document.querySelector("output").textContent = result.snapshotLength; </script>
运行结果:
点击运行 »