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