如何在 JavaScript 中呼叫函式?
JavaScript 同樣允許我們編寫自己的函式。要稍後在指令碼中的另一個位置呼叫函式,你只需編寫該函式的名稱即可。
示例
你可以嘗試執行以下程式碼來了解如何在 JavaScript 中呼叫函式−
<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>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP