如何獲取所有 jQuery 事件的列表?


事件是你的 Web 應用程式可以檢測到的操作。觸發這些事件後,你就可以使用自定義函式使用該事件做任何你想要的事情。這些自定義函式呼叫事件處理程式。

示例

讓我們看一個 jQuery 事件 bind() 的示例。使用 jQuery 事件模型,我們可以透過 bind() 方法在 DOM 元素上建立事件處理程式,如下所示:

線上演示

<html>

   <head>
      <title>jQuery bind()</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
       
      <script>
         $(document).ready(function() {
            $('div').bind('click', function( event ){
               alert('Hi there!');
            });
         });
      </script>
       
      <style>
         .div {
             margin:10px;
             padding:12px;
             border:2px solid #666;
             width:60px;
         }
      </style>
   </head>
   
   <body>
   
      <p>Click on any square below to see the result:</p>
       
      <div class = "div" style = "background-color:blue;">ONE</div>
      <div class = "div" style = "background-color:green;">TWO</div>
      <div class = "div" style = "background-color:red;">THREE</div>
       
   </body>
   
</html>

 以下是一些 jQuery 事件的列表:

序列號
事件型別和描述
1.
失去焦點
當元素失去焦點時發生。
2.
更改
當元素更改時發生。
3.
點選
當滑鼠點選時發生。
4.
雙擊
當滑鼠雙擊時發生。
5.
按鍵
當按下按鍵時發生。
6.
滾動
當視窗滾動時發生。

更新於:11-Dec-2019

223 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

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