<!DOCTYPE html>
<html>
<head>
<style>
a[target] {
background-color: yellow;
}
#myDIV {
border: 1px solid black;
}
</style>
</head>
<body>
<p>CSS 选择器 a[target] 确保所有设置 target 属性的链接都获得黄色背景:</p>
<div id="myDIV">
div 中的三个链接:
<a href="https://www.w3school.com.cn">w3school.com.cn</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()">试一试</button>
<script>
function myFunction() {
var x = document.getElementById("myDIV");
x.querySelector("a[target]").style.border = "10px solid red";
}
</script>
</body>
</html>