How would you unbind all jQuery events from a particular namespace?

前端 未结 7 1273
半阙折子戏
半阙折子戏 2021-02-06 22:50

Is there a \"global\" unbind function in jQuery, such that I\'d be able to remove all bound events from a given namespace? eg:

// assume these are the events bou         


        
7条回答
  •  盖世英雄少女心
    2021-02-06 23:23

    You need to hack into jQuery internals, here's a working demo of a simple implementation:

    http://jsfiddle.net/nkMQv/1/

    The main work is done in regular js loops and shouldn't be very inefficient as even this page contains ultimately only 106 items to loop through. You should of course use event delegation as much as possible to keep the amount of items in the jQuery handler collection as small as possible.

提交回复
热议问题