使用JavaScript,您可以在调用函数时传递不同的参数。这些传递的参数可以在函数内部捕获,并且可以对这些参数进行任何操作。一个函数可以采用多个参数,并用逗号分隔。
您可以尝试运行以下代码,以了解如何向JavaScript函数添加参数-
<html> <head> <script> function sayHello(name, age) { document.write (name + " is " + age + " 岁。"); } </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type = "button" onclick = "sayHello('John', 27)" value = "Details"> </form> </body> </html>