執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
前往 Spaces
<!DOCTYPE html> <html> <style> a[target] {background-color: yellow} </style> <body> <h1>The Document Object</h1> <h2>The querySelectorAll() Method</h2> <p>The CSS selector a[target] gives links with a target a yellow background.</p> <p>Add a red border to all links with a target attribute.</p> <a href="https://w3schools.tw">w3schools.com</a> <a href="http://www.disney.com" target="_blank">disney.com</a> <a href="http://www.wikipedia.org" target="_top">wikipedia.org</a> <script> const nodeList = document.querySelectorAll("a[target]"); for (let i = 0; i < nodeList.length; i++) { nodeList[i].style.border = "10px solid red"; } </script> </body> </html>