下面的代码演示了JavaScript中如何定义一个带参数的函数,并点击按钮调用该函数
<!DOCTYPE html> <html> <body> <p>Click the button to call a function with arguments</p> <button onclick="myFunction('Harry Potter','work for 75271.com')">Try it</button> <script> function myFunction(name,job) { alert("Welcome " + name + ", the " + job); } </script> </body> </html>