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

时间:2022-06-30 07:41:36

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>