jquery: how to remove the handler setup by .click()?
I found sometimes I hook up 2 functions to the buttun, using .click(function(){}),开发者_StackOverflow is it possible for me to remove the prior attached function before I hook up new one?
Not using an anonymous delegate like that. You can .unbind a named function though.
UPDATE
Actually you can call .unbind() with no arguments to remove all handlers or .unbind('click') to remove all handlers for a particular event.
jQuery has unbind()
There are 2 ways:
function foo(){
//do stuff
}
function bar(){
//do more
}
jQ.click(foo).click(bar);
jQ.unbind(foo);
or
jQ.bind('click.foo', function(){
//do stuff
});
jQ.click(function(){
//do more
});
jQ.unbind('.foo');
精彩评论