我試圖通過其獨特的屬性回傳所需的元素。為此,我需要使用類似此代碼的內容。我有一個錯誤,我如何使這個條目正確?
document.querySelector('div[ style*="text-decoration:line-through"]')
uj5u.com熱心網友回復:
您需要分離屬性選擇器:
document.querySelector('div[][style*="text-decoration:line-through"]');
另請注意,當您使用類來定位元素時,請使用類選擇器以獲得更好的性能:
document.querySelector('div.className[style*="text-decoration:line-through"]');
最后,您的style
選擇器非常脆弱,而且很容易損壞。例如,如果有人有效使用text-decoration: line-through
,則不會匹配。我強烈建議您使用一個類來應用樣式并選擇元素。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/507718.html
標籤:javascript 查询选择器
上一篇:優先將元素推送到陣列
下一篇:根據url匹配顯示不同的按鈕