“Alt”键盘事件在Firefox上无效 [英] 'Alt' keyup event don't work on Firefox
本文介绍了“Alt”键盘事件在Firefox上无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试捕获此键:alt +箭头向下,alt +箭头向上。
首先,我捕获alt键:
i try to capture this key : alt+arrow down, alt+arrow up. First, i capture alt key down :
var isAlt = false;
$(document).keydown(function (e) {
if(e.which == 18){isAlt=true;}
}).keyup(function (e) {
if(e.which == 18){isAlt=false;}
});
此代码正常,并检测到alt keyup。
this code is ok, and alt keyup is detected.
但是,如果我添加箭头键,当箭头键下来,没关系,但是没有检测到alt键盘之后:
But, if i add arrow key down, when arrow keydown, it's ok, but after alt keyup is not detected :
var isAlt = false;
$(document).keydown(function (e) {
if(e.which == 18){isAlt=true;}else{
if(e.which == 38 && isAlt == true) {
//action code here work
console.log('action ok');
}
}
}).keyup(function (e) {
if(e.which == 18){isAlt=false;}
});
您可以在控制台上尝试此操作,并且在记录action ok之后,您需要再次按Alt键forisAlt = false。
但是,这个代码在Chrome上可以正常工作。
You can try this on console, and after log 'action ok', you need press again alt key for "isAlt = false". But, this code work fine on Chrome.
任何人都有一个想法来纠正这个错误?
Anyone have one idea for correct this bug ?
推荐答案
您需要检查 event.altKey
属性: https://developer.mozilla.org/en/DOM/KeyboardEvent
这篇关于“Alt”键盘事件在Firefox上无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文