How to order events bound with jQuery

后端 未结 12 1187
闹比i
闹比i 2020-11-22 13:09

Lets say I have a web app which has a page that may contain 4 script blocks - the script I write may be found in one of those blocks, but I do not know which one, that is ha

12条回答
  •  -上瘾入骨i
    2020-11-22 13:33

    If order is important you can create your own events and bind callbacks to fire when those events are triggered by other callbacks.

    $('#mydiv').click(function(e) {
        // maniplate #mydiv ...
        $('#mydiv').trigger('mydiv-manipulated');
    });
    
    $('#mydiv').bind('mydiv-manipulated', function(e) {
        // do more stuff now that #mydiv has been manipulated
        return;
    });
    

    Something like that at least.

提交回复
热议问题