document.onmousedown = function( e ){
alert(getButton (e)) // e.button W3C is to get the mouse button 0 means left button 1 means middle button 2 means right button and IE browser is 1 means left button 4 means middle 2 means right button The IE browser here is mainly IE8 or below browser
};
function getButton(e){
/*
1. The window.event attribute is supported by IE and Chrome
2. But Chrome also supports W3C
3. Therefore, if both W3C and IE support it, then W3C has been standardized
*/
if( e ){ // As the first judgment, Chrome will use W3C as the standard.
return e.button;
}else if( window.event ){
switch( window.event.button ){
case 1 : return 0; // Return the value of the left mouse button
case 4 : return 1; // Return the value of the middle mouse button
case 2 : return 2; // Return the value of the right mouse button
case 0 : return 2; // Return the value of the right mouse button mainly The 360 browser will return the 0 returned in the IE browser, which represents the value returned when the mouse button is not pressed.
};
};
};