是否可以从具有多个处理程序的事件中删除一个特定的事件处理程序? [英] Is it possible to remove one specific event handler from an event with multiple handlers?

查看:57
本文介绍了是否可以从具有多个处理程序的事件中删除一个特定的事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我搜索我现在有的问题的解决方案时,我发现了此线程:

As i searched for the solution of a problem i have right now, i found this thread: jQuery: more than one handler for same event. Now i wonder if it is possible to remove just a single one of these handlers?

推荐答案

如果您使用匿名回调,则有可能:

It is possible, if you don't use anonymous callbacks:

var $elt = $(...);

function clickHandler1(event){...}
function clickHandler2(event){...}

// bind both
$elt.click(clickHandler1);
$elt.click(clickHandler2);

// unbind just the first
$elt.unbind('click', clickHandler1);

出现了一个疯狂的演示!

另请参阅: .unbind()文档.

See also: .unbind() docs.

这篇关于是否可以从具有多个处理程序的事件中删除一个特定的事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆