2011-08-11 64 views
2

如何從.keydown()函數檢索所有功能?如何檢索.keydown()函數

我需要檢索的功能,清除它並添加新的功能,並在端部輥又回到了原點功能

我沒有原點功能的處理函數,所以我不能用綁定()和unbind()我覺得..

回答

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

}); 
+0

@clarkk - 這篇幫助你嗎? – ShankarSangoli

+0

是的,它確實...... :) – clarkk