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