How can you "extend" or add more functionality to a .keydown()?
Lets say you already got this:
input.keydown(function(){
alert('key pressed');
});
How can you then later on add one more alert()?
alert('e开发者_运维问答xtra functionality');
just:
input.keydown(function(){
alert('extra functionality');
});
When an event reaches an element, all handlers bound to that event type for the element are fired. If there are multiple handlers registered, they will always execute in the order in which they were bound. After all handlers have executed, the event continues along the normal event propagation path.
http://api.jquery.com/bind/
if you need a possibility to unbind it later use:
var handler = function() {
alert('The quick brown fox jumps over the lazy dog.');
};
$('#foo').bind('click', handler);
$('#foo').unbind('click', handler);
http://api.jquery.com/unbind/
精彩评论