运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The querySelectorAll() Method</h2> <p>Add a red border to all links in "myDIV" with a target attribute:</p> <div id="myDIV"> <a href="https://w3schools.org.cn">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> </div> <script> const element = document.getElementById("myDIV"); const list = element.querySelectorAll("a[target]"); for (let i = 0; i < list.length; i++) { list[i].style.border = "10px solid red"; } </script> </body> </html>