How to order events bound with jQuery

后端 未结 12 1269
闹比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条回答
  •  再見小時候
    2020-11-22 13:39

    JQuery 1.5 introduces promises, and here's the simplest implementation I've seen to control order of execution. Full documentation at http://api.jquery.com/jquery.when/

    $.when( $('#myDiv').css('background-color', 'red') )
     .then( alert('hi!') )
     .then( myClickFunction( $('#myID') ) )
     .then( myThingToRunAfterClick() );
    

提交回复
热议问题