jQuery: Unbind event handlers to bind them again later

前端 未结 7 1014
Happy的楠姐
Happy的楠姐 2020-11-27 03:58

Does anybody know how to unbind set of event handlers, but memorize them in order to bind them again later? Any suggestions?

7条回答
  •  广开言路
    2020-11-27 04:49

    There is a events element in the data of the item. This should get your started, you can read your elements and store the handlers in an array before unbinding. Comment if you need more help. I got this idea from reading the $.fn.clone method so take a look at that as well.

    $(document).ready(function() {
        $('#test').click(function(e) {
            alert('test');
            var events = $('#test').data("events");
            $('#test').unbind('click', events.click[0]);
        });
    });
    
    test
    

提交回复
热议问题