如何在jquery中使用单个undelegate方法删除多个事件委托 [英] How to remove multiple event delegates using single undelegate method in jquery

查看:67
本文介绍了如何在jquery中使用单个undelegate方法删除多个事件委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使以下内容更简单(而不是两次使用'undelegate')吗?

Can I make the following much simpler (instead of using 'undelegate' twice)?

$("#div1").undelegate("div", "mouseenter").undelegate("div", "mouseleave");

我不希望除了mouseenter和mouseleave之外的事件处理程序受到干扰。

I don't want event handlers other than mouseenter and mouseleave to get disturbed.

推荐答案

用空格拆分事件。

$("#div1").undelegate("div", "mouseenter mouseleave");

你应该在和<$ c上使用 $ c> off 但是。

$("#div1").off("mouseenter mouseleave", "div");

http: //api.jquery.com/undelegate/


.undelegate()方法是一种删除事件处理程序的方法使用.delegate()绑定
。从jQuery 1.7开始,.on()和.off()
方法首选用于附加和删除事件处理程序。

The .undelegate() method is a way of removing event handlers that have been bound using .delegate(). As of jQuery 1.7, the .on() and .off() methods are preferred for attaching and removing event handlers.

这篇关于如何在jquery中使用单个undelegate方法删除多个事件委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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