开发者

how to retrieve .keydown() function

How is it possible to retrieve all functionality from a .keydown() function?

I need to retrieve the function, clear it and add a new function and in the end roll back to the origin func开发者_如何学编程tion

I don't have the origin function as a handler function so I can't use bind() and unbind() I think..


Try this

//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);
  });

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜