onclick - 单击按钮时
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function myFunction() {
- document.getElementById("demo").innerHTML = "Hello World";
- }
- </script>
- </head>
- <body>
- <p>单击按钮以触发函数。</p>
- <button onclick="myFunction()">点击这里</button>
- <p id="demo"></p>
- </body>
- </html>