JavaScript允许我们编写自己的函数。要在脚本后面的某个地方调用一个函数,您只需要编写该函数的名称即可。
您可以尝试运行以下代码以了解如何在JavaScript中调用函数-
<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>