如何點選 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>

更新於:2020-06-19

1 千次觀看

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.