簡體   English   中英

從JQUERY Keydown活動取消注冊

[英]Unregistering from the JQUERY Keydown event

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

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

當我使用以下代碼時:

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

它會引發以下錯誤:

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

有人能指出我從keydown事件中取消注冊的正確方法嗎?

取消綁定document所有keydown處理程序:

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

或者確保您只取消綁定該特定處理程序:

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

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

http://api.jquery.com/unbind

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM