Result Size: 625 x 534
x
 
<!DOCTYPE html>
<html>
<body>
<a id="myAnchor">链接:前往begtut.com</a>
<p>点击按钮设置上面a元素的href属性值为“www.begtut.com”。</p>
<button onclick="myFunction()">试一试</button>
<p><strong>注意:</strong>Internet Explorer 8 及更早版本不支持 setAttribute 方法。</p>
<script>
function myFunction() {
  document.getElementById("myAnchor").setAttribute("href", "https://www.begtut.com"); 
}
</script>
</body>
</html>