2011-04-29 24 views
5

Duplicar posible:
Jquery: detect if middle or right mouse button is clicked, if so, do this:¿Alerta de Jquery cuando se hace clic en el botón central del mouse?

¿Cómo demuestro cuadro de alerta que dice "botón central del ratón hace clic" cuando hago clic en el texto, o cualquier elemento DOM? Quiero ser capaz de diferenciar entre el mouse del medio y el clic derecho normal usando jquery/javscript.

me refiero a esto: Jquery: detect if middle or right mouse button is clicked, if so, do this:

y modificar el violín js a esto: http://jsfiddle.net/zAGLP/29/

Pero estoy buscando una alternativa a ") en vivo (" función.

+0

Estás preguntando cómo hacer esto sin que vivo, y en cualquier texto? Mi respuesta debería ser suficiente. – Mario

Respuesta

13
$(document).bind('mousedown', function(e) { 
    if((e.which == 1)) { 
    alert("left button"); 
    }if((e.which == 3)) { 
    alert("right button"); 
    }else if((e.which == 2)) { 
     alert("middle button"); 
    } 
    e.preventDefault(); 
}).bind('contextmenu', function(e){ 
e.preventDefault(); 
}); 
Cuestiones relacionadas