JavaScript 语句可以在代码块中组合在一起

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h2>JavaScript 语句</h2>
  6.  
  7. <p>JavaScript 代码块在 { 与 } 之间编写。</p>
  8.  
  9. <button type="button" onclick="myFunction()">点击我!</button>
  10.  
  11. <p id="demo1"></p>
  12. <p id="demo2"></p>
  13.  
  14. <script>
  15. function myFunction() {
  16. document.getElementById("demo1").innerHTML = "Hello Kitty.";
  17. document.getElementById("demo2").innerHTML = "How are you?";
  18. }
  19. </script>
  20.  
  21. </body>
  22. </html>