在'click'事件中检查Ctrl / Shift / Alt键 [英] Check Ctrl / Shift / Alt keys on 'click' event

查看:186
本文介绍了在'click'事件中检查Ctrl / Shift / Alt键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在以下代码中识别哪个 Ctrl / Shift / Alt 键?

  $(#my_id)。click(function(){
if(< left control key pressed> ;){alert(Left Ctrl);}
if(< right shift and left alt keys are pressed>){alert(Right Shift + Left Alt);}
});


解决方案

。微软实现了确定哪个(右/左)键被按下的能力。这里是一个链接 http://msdn.microsoft.com/ en-us / library / ms534630(VS.85).aspx

我还在浏览器中发现了这篇关于按键,按键,按键事件的文章。
http://unixpapa.com/js/key.html



$ $ $ $'code $('#someelement')。bind('click',function(event){

if .ctrlKey){
if(event.ctrlLeft){
console.log('ctrl-left');
}
else {
console.log(' ctrl-right');
}
}
if(event.altKey){
if(event.altLeft){
console.log('alt-left ');
}
else {
console.log('alt-right');
}
}
if(event.shiftKey){
if(event.shiftLeft){
console.log('shift-left');
}
else
{
console.log('右移');
}
}
});


How could I identify which Ctrl / Shift / Alt keys are pressed in the following code ?

$("#my_id").click(function() {
    if (<left control key is pressed>) { alert("Left Ctrl"); }
    if (<right shift and left alt keys are pressed>) { alert("Right Shift + Left Alt"); }
});

解决方案

Well you this wont work in all browsers just IE 8. Microsoft implemented the ability to determine which (right/left) key was pressed. Here is a link http://msdn.microsoft.com/en-us/library/ms534630(VS.85).aspx

I also found this wonder article about keypress, keyup, keydown event in browsers. http://unixpapa.com/js/key.html

$('#someelement').bind('click', function(event){ 

    if(event.ctrlKey) {
      if (event.ctrlLeft) {
        console.log('ctrl-left'); 
      }
      else {
        console.log('ctrl-right');
      }
    }
    if(event.altKey) {
      if (event.altLeft) {
        console.log('alt-left'); 
      }
      else {
        console.log('alt-right');
      }
    }
    if(event.shiftKey) {
      if (event.shiftLeft) {
        console.log('shift-left'); 
      }
      else
      {
        console.log('shift-right');
      }
    }
  }); 

这篇关于在'click'事件中检查Ctrl / Shift / Alt键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆