如何从JavaScript函数返回值?
要从JavaScript函数返回值,请使用JavaScript中的return语句。您需要运行以下代码以了解如何返回值-
示例
<html> <head> <script> function concatenate(name, age) { var val; val = name + age; return val; } function DisplayFunction() { var result; result = concatenate('John ', 20) ; document.write (result ); } </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type = "button" onclick = "DisplayFunction()" value = "Result"> </form> </body> </html>