如何使用 jQuery 處理滑鼠右鍵單擊事件?
要處理滑鼠右鍵單擊事件,請使用jQuery mousedown()方法。使用相同的方法也可以捕獲滑鼠左鍵、右鍵和中鍵單擊。你可以嘗試執行以下程式碼來學習如何處理滑鼠右鍵單擊事件
示例
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('.myclass').mousedown(function(event) { switch (event.which) { case 1: alert('Left mouse button is pressed'); break; case 2: alert('Middle mouse button is pressed'); break; case 3: alert('Right mouse button is pressed'); break; default: alert('Nothing'); } }); }); </script> </head> <body> <a href="http://qries.com" class="myclass">Click me</a> </body> </html>
廣告