博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JQuery多个异步操作后执行(resolve,promise,when,done)
阅读量:5068 次
发布时间:2019-06-12

本文共 826 字,大约阅读时间需要 2 分钟。

代码分享:

//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);})

 

转载于:https://www.cnblogs.com/kandyvip/p/10948902.html

你可能感兴趣的文章