无法访问firefox中的Event.repeat

时间:2017-10-19 11:19:36

标签: javascript jquery events

这不是Firefox "window.event is undefined" error

的重复

我有这段代码:

 $(window).on('keydown keyup', function(e){
       e.preventDefault();
       var repeat = window.event.repeat
       console.log(repeat); // Works in chrome
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Click here and hold down a key

在chrome中它可以正常工作(如果按住键,我得到true,否则返回false),但是在firefox中我得到这个错误:TypeError: window.event is undefined因为不支持window.event,但是后来我找到重复 is supported in firefox

我尝试使用变量e,但它甚至不能用于chrome:

 $(window).on('keydown keyup', function(e){
       e = e || window.event;
       var repeat = e.repeat
       console.log(repeat); // In this case repeat is always undefiend
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Click here and hold down a key

如何在Firefox中访问Event.repeat属性?

0 个答案:

没有答案