jQuery处理按键组合 [英] jQuery handling keypress combinations
本文介绍了jQuery处理按键组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道当 keypress
事件发生时,我们可以访问对象的事件属性 keycode
按下哪个键,但我需要知道如何通过jQuery处理 keypress
组合,如 ctrl + D
..etc?
I know that when keypress
event occurs then we can access which key is pressed by object's event property keycode
, but I need to know how do we can handle keypress
combinations through jQuery like ctrl + D
..etc?
在下面的代码中,我尝试做类似的事情:
In the following code I tried to do something like :
$(document).on("keypress", function(e) {
if( /* what condition i can give here */ )
alert("you pressed cntrl + Del");
});
推荐答案
jQuery已经为您解决了这个问题:
jQuery already handles this for you:
if ( e.ctrlKey && ( e.which === 46 ) ) {
console.log( "You pressed CTRL + Del" );
}
这篇关于jQuery处理按键组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文