问题描述
function1 = function(){
something.on('transitionend', function(){
// now function2 should run
});
}
function2 = function(){
alert('ok');
}
function1();
function2();
所以我听说了 jQuery 承诺.我将返回一个延迟"对象,并在事件处理程序中调用 deferred.resolve();
So I heard about jQuery promises. I would return a "deferred" object, and inside the event handler I would call deferred.resolve();
但是如果我在那里有多个事件处理程序并且我只想在所有事件都被触发后运行下一个函数会发生什么?+ 我不喜欢在代码的其他部分引入诸如延迟"之类的外来内容.
But what happens if i have multiple event handlers there and I only want the next function to run when all have been fired? + I don't like the idea of introducing something foreign like "deferred" into other parts of the code.
有没有其他方法可以检测 function1 是否完成了所有工作?
Is there any other way to detect if function1 has finished all its work?
推荐答案
试试这个,
$.when($.ajax(fuction1())).then(function () {
fuction2;
});
这里 fuction1 是您要调用的第一个函数,而 fuction2 是您要调用的第二个函数.
Here fuction1 is your first function to call, and fuction2 is your second function.
这篇关于另一个完成后运行函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)