编辑下面的代码:【加编码】
<html> <head> <style> a[target] { background-color: yellow; } div { border: 1px solid black; } </style> </head> <body> <p> CSS 选择器 a[target] 确保所有带有 target 属性的背景色设置为黄色:</p> <div id="myDIV"> Three links inside div: <a href="/">ziqiangxuetang.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> <p>点击按钮为 div 元素中带有 target 属性的第一个属性设置红色边框。</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var x = document.getElementById("myDIV"); x.querySelector("a[target]").style.border = "10px solid red"; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂