开发者

Excluding form elements on keypress

开发者 https://www.devze.com 2023-03-12 23:34 出处:网络
I have a keypress assigned to a div, for example pressing A will show the div, press again to hide, problem is this also happens in form elements,开发者_开发知识库 have looked at other questions and a

I have a keypress assigned to a div, for example pressing A will show the div, press again to hide, problem is this also happens in form elements,开发者_开发知识库 have looked at other questions and answers but none worked for me.

I'm using:

$(document).keypress(function(ev) {
if (ev.which === 65 || ev.which === 97) { // 'A' or 'a'
     $('#mainMenu').toggle();
}
});

How can I exclude textfields from this?


check the ev.target

something like:

if ($(ev.target).is(":input")) {
    return;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消