如何从.keydown()函数中检索所有功能?
我需要检索函数,清除它并添加一个新函数,最后回滚到原始函数
我没有origin函数作为处理函数,所以我不能使用bind()和unbind()我认为..
答案 0 :(得分:3)
试试这个
//This will retrieve all the keydown events attached to the element
var originalKeydownEvents = $('elementSelector').data("events").keydown;
//Here unbind all the keydown handlers and bind the required keydown handler
$("elementSelector").unbind('keydown').keydown(function(){
var $this = $(this);
//Do you stuff here
//Then finally attach the original events
jQuery.each(originalKeydownEvents, function(key, handler) {
$this.keydown(handler);
});
});