2016-02-07 65 views

回答

4

使用jquery的event.which正常化event.keyCodeevent.charCode因此您不必担心浏览器兼容性问题。文档上event.which

event.which将给予1,2或3的左,中,右鼠标键分别为这样:

$('#element').mousedown(function(event) { 
    switch (event.which) { 
     case 1: 
      console.log('Left Mouse button pressed.'); 
      break; 
     case 2: 
      console.log('Middle Mouse button pressed.'); 
      break; 
     case 3: 
      console.log('call your controller'); 
      break; 
     default: 
      console.log('You have a strange Mouse!'); 
    } 
}); 
+0

非常感谢它一直 –

相关问题