开发者

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');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜