You're right. You need a mousedown
or mouseup
event to determine which mouse button was actually clicked.
But first of all, you need to get rid of that inline-event handler onclick
and follow the shining road of unobtrusive javascript.
Thatfor you need to give that anchor a id
or class
tag to identify it (Of course you may also choose to select that anchor with a css selector). Lets assume we have added a class with the name myClazzz :)
javascript:
$(function(){
$('.myClazzz').bind('mouseup', function(e){
switch(e.which){
case 1:
alert('Left Mouse button pressed.');
break;
case 2:
alert('Middle Mouse button pressed.');
break;
case 3:
alert('Right Mouse button pressed.');
break;
default:
alert('You have a strange Mouse!');
}
});
});
The which
property within a mousedown
/ mouseup
event handler will contain a number which indicates which mousebutton was clicked.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…