jQuery 'KeyDown' 事件问题 - 快速键入

jQuery 'KeyDown' Event issue - Fast Typing

我正在使用 jQuery 按键事件来检测键码,这反过来有助于防止某些操作。

有一个输入字段 class '.donothack' 如下所示

<input name="hac" class="donothack" id="donothack" value="" />

在jQuery中提到的代码如下

$(".donothack").on("keydown", function(event) {
    console.log(event.keyCode);
    if(event.shiftKey && event.keyCode != 9 || event.keyCode != 9) { 
        //Stop operation
    }
}

Now the problem is that when someone types too fast in this input field then Every event on browser is hanged and he has to manually kill the browser or page through Task Manager of computer.

我刚刚决定 console.log 然后我发现事件正在像任何东西一样增加。如下图所示,计数是无止境的。 而且我什至不知道我按下了多少次按键:(

请提出解决方案?

试试这个

$(".donothack").unbind("keydown").on("keydown", function(event) {
    console.log(event.keyCode);
    if(event.shiftKey && event.keyCode != 9 || event.keyCode != 9) { 
        //Stop operation
    }
}