jQuery 右鍵事件


鼠標右鍵事件(jQuery)

  2種寫法:

    1.  .contextmenu()
      1    <script>
      2       // 鼠標右鍵事件
      3       $(document).contextmenu(function(e) {
      4          e.preventDefault() // 阻止右鍵菜單默認行為
      5          console.log('this' + this)
      6          console.log('e' + e)
      7          console.log('e.target' + e.target)
      8       })
      9    </script> 

       

    2. mouseDown + e.which
       1 <script>
       2      $(document).mousedown(function(e) {
       3          //alert(e.which) // 1 = 鼠標左鍵 left; 2 = 鼠標中鍵; 3 = 鼠標右鍵
       4          if (e.which == 3) {
       5              e.preventDefault() // 阻止默認行為
       6              console.log('this' + this)
       7              console.log('e' + e)
       8              console.log('e.target' + e.target)
       9          }
      10      })
      11 </script>

       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM