從JQUERY Keydown事件取消注冊。

[英]Unregistering from the JQUERY Keydown event


I am trying to remove the keydown event that I have created using the following code:

我正在嘗試刪除我使用以下代碼創建的keydown事件:

$(document).keydown(function(e) {
    alert("Key Down");
});

when I am using the following code:

當我使用以下代碼時:

$(document).off('keydown');

it throws the following error:

它拋出以下錯誤:

Uncaught TypeError: Object [object Object] has no method 'off'

can someone point me to the correct way to un-register from the keydown event?

有人能告訴我正確的從按鍵事件中取消注冊的方法嗎?

1 个解决方案

#1


13  

Unbind all keydown handlers from document:

從文檔中解綁定所有keydown處理程序:

$(document).unbind('keydown');

Or to make sure you only unbind that specific handler:

或者確保你只解綁定那個特定的處理器:

function myHandler(e) {
    alert("Key Down");
}

$(document).keydown(myHandler);
// later
$(document).unbind('keydown', myHandler);

http://api.jquery.com/unbind

http://api.jquery.com/unbind


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/11/04/72a1a3629a16a52b91016b44c5a9dda4.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com