Javascript jQuery:如何删除所有委托事件

Javascript jQuery:如何删除所有委托事件,javascript,jquery,Javascript,Jquery,在我的程序中,我使用主体来委派网页中的所有事件。我如何删除这些事件?这是我的密码,谢谢 jQuery(function ($) { $("body").on("mouseenter.noteEvent", "*", function (event) { //doSomeThing(); }); $("body").on("mouseleave.noteEvent", "*", function (event) { //doSomeThing()

在我的程序中,我使用
主体
来委派网页中的所有事件。我如何删除这些事件?这是我的密码,谢谢

jQuery(function ($) {

  $("body").on("mouseenter.noteEvent", "*", function (event) {
        //doSomeThing();
    });

  $("body").on("mouseleave.noteEvent", "*", function (event) {
        //doSomeThing();
    });

 $("body").on("click.noteEvent", "*", function (event) {
        //doSomeThing();
    });

});
还有移除事件功能,但失败了,有什么建议吗

 var removeEvent = function(){

    jQuery("body").off(".noteEvent", "*"); // '*' or '**' ?
    //jQuery("body").off(".noteEvent", "**"); 
};

您可以使用以下命令删除事件:

$("body").off("mouseenter.noteEvent");
或者,如果您使用:

$("body").off("mouseenter");
然后将删除所有的
mouseenter
事件。您也可以使用:

// Remove all event handlers from all paragraphs:
$("p").off();

// Remove all delegated mouseenter handlers from all paragraphs:
$("p").off("mouseenter", "**");

// Remove event handlers in the ".noteEvent" namespace
$("body").off(".noteEvent");

阅读更多信息。

按命名空间解除所有委托事件处理程序的绑定时,只需执行以下操作:

jQuery("body").off(".noteEvent"); // only specify the namespace.