带一个参数的函数

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p>单击“试一试”以使用参数来调用函数</p>
  6.  
  7. <button onclick="myFunction('Harry Potter','Wizard')">试一试</button>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. function myFunction(name,job) {
  13. document.getElementById("demo").innerHTML = "Welcome " + name + ", the " + job + ".";
  14. }
  15. </script>
  16.  
  17. </body>
  18. </html>