我知道当 keypress
事件发生时,我们可以通过对象的事件属性 keycode
访问按下哪个键,但我需要知道如何处理 keypress
通过 jQuery 进行组合,例如 ctrl + D
..等?
在下面的代码中我尝试做类似的事情:
$(document).on("keypress", function(e) {
if( /* what condition i can give here */ )
alert("you pressed cntrl + Del");
});
最佳答案
jQuery 已经为您处理了这个问题:
if ( e.ctrlKey && ( e.which === 46 ) ) {
console.log( "You pressed CTRL + Del" );
}
关于javascript - jQuery 处理按键组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10671822/