Note: keyCode
is getting deprecated use key
instead.(注意: keyCode
正在被弃用的使用key
。)
function keyPress (e) {
if(e.key === "Escape") {
// write your logic here.
}
}
Here is jsfiddle(这是jsfiddle)
keyCode
is Getting deprecated(keyCode
已弃用)
It seems keydown
and keyup
work, even though keypress
may not(它似乎是keydown
和keyup
工作,即使keypress
可能没有)
$(document).keyup(function(e) {
if (e.key === "Escape") { // escape key maps to keycode `27`
// <DO YOUR WORK HERE>
}
});
Which keycode for escape key with jQuery(使用jQuery的escape key的哪个键代码)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…