語法
js
createExpression(xpathText, namespaceURLMapper)
引數
xpathText-
一個字串,表示要編譯的 XPath 表示式。
namespaceURLMapper-
一個函式,用於將名稱空間字首對映到名稱空間 URL(如果不需要則為 null)。
返回值
XPathExpression
示例
js
const xpathExpr = document.createExpression("//div");
const xpathResult = xpathExpr.evaluate(document); // returns an XPathResult object
const nodeContext = document.querySelector("nav");
// Re-using the XPathExpression "xpathExpr"
const otherResult = xpathExpr.evaluate(nodeContext); // returns an XPathResult object
規範
| 規範 |
|---|
| DOM # dom-xpathevaluatorbase-createexpression |
瀏覽器相容性
載入中…