3
我試圖獲取具有以「temp」開頭的屬性名稱的數組(不是屬性值,或者我是使用querySelectorAll
)。獲取具有使用XPath的特定名稱以特定字符串開頭的元素的列表
但是,似乎我無法完全正確地獲取xpath表達式。這裏是什麼似乎是我想出來的最接近:
let els = Array.from(document.evaluate(
`//*/@*[starts-with(name(.), 'temp')]`,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue);
console.log(els);
<div temp-callback="1" temp-post-callback="4"></div>
<div temp-callback="2"></div>
<div></div>
<div temp-callback="8" temp-post-callback="7"></div>
我會假設,會給我3周的div包含至少1屬性「溫度」。
我錯過了什麼?
啊,OK。這更有意義。謝謝 – KevBot