<html><body><h1>Element 对象</h1><h2>setAttribute() 方法</h2><a id="myA" href="https://www.w3school.com.cn" target="_blank">W3school</a>.<p>单击“更改”可将链接目标更改为 "_self_"。</p><button onclick="myFunction()">更改</button><p>请尝试在“更改”前后点击链接。</p><script>function myFunction() { const element = document.getElementById("myA"); if (element.hasAttribute("target")) { element.setAttribute("target", "_self"); }}</script></body></html>