<!DOCTYPE html> <html> <body> <h1>Element 对象</h1> <h2>setAttribute() 方法</h2> <a id="myAnchor">访问 sou-xun.com</a> <p>单击“添加”为上面的元素添加一个 href 属性。</p> <button onclick="myFunction()">试一试</button> <script> function myFunction() { document.getElementById("myAnchor").setAttribute("href", "https://www.sou-xun.com"); } </script> </body> </html>