按键事件不能在IE和Chrome中工作,但在FF中工作 [英] keypress event not working in IE and Chrome but working in FF
问题描述
$ $ $(document).keypress(function(e){ ();
if(e.keyCode == 37)leftImage();
});
这就是我的按键的样子。我错过了什么吗?右图();和leftImage();是功能,应该工作,因为我在其他地方使用这些功能
感谢您的帮助!
更改按键
到 keydown
:
$(document).keydown(function(e){
if(e.keyCode == 39)rightImage();
if (e.keyCode == 37)leftImage();
});
请参阅 http://www.bloggingdeveloper.com/post/KeyPress-KeyDown-KeyUp-The-Difference-Between-Javascript-Key -Events.aspx 两者之间的解释。
Any idea why this might happen? I would usually think that Chrome would be more forgiving with the codes?
$(document).keypress(function(e) {
if(e.keyCode == 39) rightImage();
if(e.keyCode == 37) leftImage();
});
Thats what my keypress key looks like. Am I missing something? rightImage(); and leftImage(); are functions which should be working becase I'm using those functions somewhere else too
Thanks for the help!
Change keypress
to keydown
:
$(document).keydown(function(e) {
if(e.keyCode == 39) rightImage();
if(e.keyCode == 37) leftImage();
});
See http://www.bloggingdeveloper.com/post/KeyPress-KeyDown-KeyUp-The-Difference-Between-Javascript-Key-Events.aspx for an explanation between the two.
这篇关于按键事件不能在IE和Chrome中工作,但在FF中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!