如何在 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>

更新於:2020 年 6 月 19 日

926 次瀏覽

開啟你的職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.