开发者

Catch only a left clicks on links [duplicate]

开发者 https://www.devze.com 2022-12-13 07:53 出处:网络
This question already has answers here: How to detect left click anywhere on the document using jQuery?
This question already has answers here: How to detect left click anywhere on the document using jQuery? (4 answers) Closed 2 years ago.

We are using event click to catch click on links and load content via ajax. But event happens also on right mouse and wheel clicks. How to process only left? confused

// jquery.coyod-engine-0.5.0.js
$(document).click(function(e){
        
        var t = $(e.target);            
        if(t.hasClass('aj'))
        {               
            
            e.stopPropagation();
            e.preventDefault();
            showContent(t.attr('href'));                  开发者_StackOverflow          
            return false;               
        }
        
        return true;
        
    });


Throw in a check at the start of you function which checks if the left button was used

//left == 0, middle == 1, right == 2
if (e.button != 0) return true;
else {
  //whatever
  return false;
}


Just add this at the begining of your callback:

if (e.button != 0) return true;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号