简体   繁体   English

触发没有响应的JQuery keydown事件

[英]Triggering a JQuery keydown event with no response

I'm having trouble triggering a keydown event for a particular letter. 我在触发特定字母的按键事件时遇到麻烦。 I've searched and still haven't found anything that's been helpful for the issue I'm having, wondering if anyone can help me out. 我进行了搜索,但仍然找不到任何对我遇到的问题有所帮助的东西,想知道是否有人可以帮助我。 I've set an alert to test it out of which I don't receive either. 我设置了一个警报以对其进行测试,但我均未收到任何警报。 I read that event.which is helpful in this case but not sure where to put, when I tried it out it didn't work. 我阅读了该事件。在这种情况下这很有用,但不确定放置在哪里,当我尝试它时不起作用。 The purpose of this it to animate an alternative .gif when this key is pressed. 这样做的目的是在按下此键时为替代的.gif动画。

$('target-class').keydown(function(event) {
    if ($(this).event.keyCode == 85) {
        alert('Press this key');
    }
//here are my <script> tags in html //
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<script src="js/app.js"></script>

Try using Keyboard js 尝试使用Keyboard js

I have used it and it's awesome if you need to bind your whole keyboard. 我用过它,如果您需要绑定整个键盘,那就太好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM