how to unbind all event using jquery

后端 未结 4 1614
时光取名叫无心
时光取名叫无心 2020-12-02 10:46

i can use this code to remove click event,

$(\'p\').unbind(\'click\')

but , has some method to remove all event ?

has a method nam

4条回答
  •  醉梦人生
    2020-12-02 11:26

    @jammypeach is right about on & off being the accepted methods to use. Unbind sometimes ends up creating weird behaviors (e.g. not actually unbinding events correctly).

    To unbind all elements within the body, find them all and for each one turn off the click handler (what was the old unbind):

    $("body").find("*").each(function() {
        $(this).off("click");
    });
    

    Also see how to save the events that you've turned off in this stack overflow question.

提交回复
热议问题