如何在 onclick 事件中呼叫多個 JavaScript 函式?


若要在點選事件中呼叫多個 JavaScript 函式,請使用以下所示的分號 -

onclick="Display1();Display2()"

示例

線上演示

<html>
   <head>
      <script>
         function Display1() {
            document.write ("Hello there!");
         }
         function Display2() {
            document.write ("Hello World!");
         }
      </script>
   </head>
   <body>
      <p>Click the following button to call the function</p>
      <form>
         <input type = "button" onclick = "Display1(); Display2()" value = "Result">
      </form>
   </body>
</html>

更新於: 2020 年 6 月 12 日

1K+ 瀏覽次數

開啟你的 職業生涯

完成本課程,獲得認證

開始學習
廣告
© . All rights reserved.