onclick - 单击按钮时

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function myFunction() {
  6. document.getElementById("demo").innerHTML = "Hello World";
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <p>单击按钮以触发函数。</p>
  13.  
  14. <button onclick="myFunction()">点击这里</button>
  15.  
  16. <p id="demo"></p>
  17.  
  18. </body>
  19. </html>