js坚持不懈之15:修改html内容和属性的方法

  • 2022-07-05 15:26:10

1. 修改 html 内容

<!doctype html>
<html>
<body>

<p id = "change">原始内容</p>

<script>

document.getelementbyid("change").innerhtml = "修改过后的内容";

</script>

</body>
</html>

2. 修改 html 属性

<!doctype html>
<html>
<body>

<a id = "change1" href = "https://www.baidu.com">这是百度</a>
<br>
<a id = "change2" href = "https://www.baidu.com">这是淘宝</a>

<script>

document.getelementbyid("change2").href = "https://www.taobao.com";

</script>

</body>
</html>

 

猜你喜欢