代码分享:
//3秒后完成function asyncThing1() { var dfd = $.Deferred(); setTimeout(function () { alert('asyncThing1 seems to be done...'); dfd.resolve('111'); }, 3000); return dfd.promise();}//5秒后完成function asyncThing2() { var dfd = $.Deferred(); setTimeout(function () { alert('asyncThing2 seems to be done...'); dfd.resolve('222'); }, 5000); return dfd.promise();}//1秒后完成function asyncThing3() { var dfd = $.Deferred(); setTimeout(function () { alert('asyncThing3 seems to be done...'); dfd.resolve('333'); }, 1000); return dfd.promise();}//全部完成后$.when(asyncThing1(), asyncThing2(), asyncThing3()).done(function (res1, res2, res3) { alert('all done!'); alert(res1 + ', ' + res2 + ', ' + res3);})