2016-02-07 63 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

非常感謝它一直 –

相關問題