x
 
<!DOCTYPE html>
<html>
<style>
a:focus, a:active {
  color: red;
}
</style>
<body>
<h1>Element 对象</h1>
<h2>focus() 和 blur() 方法</h2>
<a id="myAnchor" href="https://www.w3school.com.cn">访问 W3School.com.cn</a>
<p>单击按钮可为上面的链接赋予或移除焦点。</p>
<input type="button" onclick="getfocus()" value="获得焦点">
<input type="button" onclick="losefocus()" value="丢失焦点">
<script>
function getfocus() {
  document.getElementById("myAnchor").focus();
}
function losefocus() {
  document.getElementById("myAnchor").blur();
}
</script>
</body>
</html>