要通过单击JavaScript中的按钮来调用函数,请使用onclick。尝试运行以下代码以在JavaScript中调用onclick函数-
<html> <head> <script> function sayHello() { document.write ("你好!"); } </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type = "button" onclick = "sayHello()" value = "Say Hello"> </form> <p>Use different text in write method and then try...</p> </body> </html>