'Alt' keyup event don't work on Firefox

两盒软妹~` 提交于 2020-01-17 04:13:22

问题


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;}
});

this code is ok, and alt keyup is detected.

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;}
});

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 ?


回答1:


You need to check the event.altKey property: https://developer.mozilla.org/en/DOM/KeyboardEvent



来源:https://stackoverflow.com/questions/9988403/alt-keyup-event-dont-work-on-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!