通过 js 修改 html 的文本内容
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>xiao001</title> 6 </head> 7 <body> 8 <h1>this is a js and html code</h1> 9 <p id = "demo">点击按钮将此处文本替换</p> 10 <button type="button" onclick="my_function()">点我</button> 11 12 <script type="text/javascript"> 13 function my_function() {//替换demo里面的文本内容 14 document.getElementById("demo").innerHTML = "Hello javascript!"; 15 } 16 </script> 17 18 </body> 19 </html>