带一个参数的函数 2

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function myfunction(txt) {
  6. document.getElementById("demo").innerHTML = txt
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <p>单击其中一个按钮时,将调用一个函数。该函数将显示传递给它的参数。</p>
  13.  
  14. <form>
  15. <input type="button" onclick="myfunction('Good Morning!')" value="In the Morning">
  16. <input type="button" onclick="myfunction('Good Evening!')" value="In the Evening">
  17. </form>
  18.  
  19. <p id="demo"></p>
  20.  
  21. </body>
  22. </html>