Result Size: 625 x 534
x
 
<!DOCTYPE html>
<html>
<head>
<style>
a[target] {
  background-color: yellow;
}
</style>
</head>
<body>
<p>CSS 选择器 a[target] 确保所有具有 target 属性的链接都获得黄色背景:</p>
<a href="https://www.begtut.com">begtut.com</a>
<a href="http://www.disney.com" target="_blank">disney.com</a>
<a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>
<p>单击该按钮可为文档中具有目标属性的所有链接添加红色边框。</p>
<button onclick="myFunction()">试一试</button>
<p><strong>注意:</strong> Internet Explorer 8 及更早版本不支持 querySelectorAll() 方法。</p>
<script>
function myFunction() {
  var x = document.querySelectorAll("a[target]");
  var i;
  for (i = 0; i < x.length; i++) {
    x[i].style.border = "10px solid red";
  }
}
</script>
</body>
</html>