开发者

Excluding form elements on keypress

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜