簡體   English   中英

通過帶有“:”(冒號)的屬性選擇元素

[英]Select elements by attributes with ":" (colon)

在我的項目中,有一個庫生成元素的情況,我需要從那里選擇特定元素 - 這些元素恰好包含一個帶有“:”的屬性。
換句話說,我最終嘗試使用: document.querySelectorAll("[xml:space]")
但是,當在 Chrome 中測試時,它不起作用,也沒有選擇使用document.querySelectorAll("['xml:space']") - 他們都拋出了DOMException
http://i.imgur.com/GrjpL85.png

我的問題是,如何使上述選擇器返回具有xml:space屬性的元素列表?
謝謝!

你需要逃離冒號

document.querySelectorAll('[xml\\3A space]')

我使用https://mothereff.in/css-escapes來獲取上面的代碼:)

轉義:通過在它前面加上雙反斜杠\\\\

document.querySelectorAll("[xml\\:space]")

看到這個:

https://bugzilla.mozilla.org/show_bug.cgi?id=883044

也可以做

document.querySelectorAll('[id="xml:space"]')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM