如何删除事件处理程序document.onkeydown? [英] How to remove an eventhandler document.onkeydown?
本文介绍了如何删除事件处理程序document.onkeydown?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码,我需要以编程方式覆盖或从文档中删除onkeydown(例如,使用简单条件)
I have this code, I would need programmatically overridde or remove onkeydown from document (for example using a simple condition)
document.onkeydown = function (f) {
myMethod();
};
有什么想法吗?
推荐答案
document.onkeydown = null
您可以使用jquery为您处理事件,所使用的方法不太常用,并且不允许多个订阅者.
You could use jquery to do your event handeling for you, the method you use is less commonly used and doesn't allow multiple subscribers.
在此处查看文档:
示例:
$(document).on("keydown", function(){
doStuff();
})
// unsubscribe all handlers
$(document).off("keydown");
这篇关于如何删除事件处理程序document.onkeydown?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文