如何单击调用 JavaScript 函数?
如要在 JavaScript 中单击某个按钮时调用某个函数,请使用 onclick。尝试运行以下代码以在 JavaScript 中单击 onclick 按钮调用一个函数 −
示例
<html> <head> <script> function sayHello() { document.write ("Hello there!"); } </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>
广告