jQuery 解除 Live/Delegate 事件与命名空间的绑定

发布于 2024-09-18 09:49:10 字数 649 浏览 2 评论 0原文

我正在尝试解除实时事件的绑定(已尝试使用 .live 和 .delegate)。

当我想解除绑定时,我有 3 个不同的选项:解除绑定 "click"、解除绑定 "click.namespace1" 或解除绑定 ".namespace1" 。它们都做不同的事情:第一个取消绑定所有单击事件(不是我想要的),第二个仅取消绑定“click”处的事件与命名空间“namespace1”(同样,这不是我想要的)。最后一个解除所有与命名空间“namespace1”绑定的事件的绑定,即使它们不是“点击”,这就是我想要的。

当您使用 .unbind(".namespace1") 时,它非常适合使用 .bind 进行绑定事件。但是当您使用 .die(".namespace1").undelegate(".namespace1") 时,它不起作用!

这是一个示例: http://jsfiddle.net/uWxpv/8/

如果有人知道,请我能做什么帮助我!

预先感谢,

迭戈

I'm trying to unbind a live event (have tried with .live and with .delegate).

When I want to unbind it I have 3 different options: unbind "click", unbind "click.namespace1" or unbind ".namespace1". They all do different things: first one unbind all click events (is not what I want), the second one unbind only the events at "click" with the namespace "namespace1" (again, is not what I want). The last one unbind all binded events with the namespace "namespace1", even if they are not "click", this is what I want.

When you use .unbind(".namespace1") it works perfectly for binded events with .bind. But when you use .die(".namespace1") or .undelegate(".namespace1") it does not work!!

Here is a sample: http://jsfiddle.net/uWxpv/8/

Please if someone know what can I do help me!

Thanks in advance,

Diego

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

客…行舟 2024-09-25 09:49:10

正确的做法是:

$(document).unbind(".namespace1");

在这里你可以尝试一下:http://jsfiddle.net/mPrsP/

The correct way to do this is:

$(document).unbind(".namespace1");

Here you can try it: http://jsfiddle.net/mPrsP/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文