源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> </head> <body> <button onclick="myFunction()">点击我</button> <p id="demo"></p> <p>当按钮被点击时,触发函数,内容输出在id="demo"的段落里</p> <script> function myFunction() { document.getElementById("demo").innerHTML = "编程字典"; } </script> </body> </html>
运行结果