如何使用jQuery。当.done [英] How to use jQuery .When .done

查看:64
本文介绍了如何使用jQuery。当.done的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在另一个函数完成后运行一个函数。

I'm trying to run one function after another function completes.

 $.when(saveCanvas(canvas)).done(setWallPaper());

每个函数都可以自行运行,但是当我运行上面的代码时,它只运行第一个函数。

Each function works fine on it's own but when I run the code above it only runs the first function.

我需要更改什么?

推荐答案

回顾现在,这似乎是它如何与jQuery一起使用:

Looking back at this now, this seems to be how it works with jQuery:

function f1() {
	alert("function one");
}

$.when( f1() ).done(function() {
  alert("function 1 is done running function two");
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

注意:这与我在问题中发布的方法相同,所以基本上应该有效。虽然jQuery可能在过去3年中发生了变化。最有可能的是调用函数的问题。

Note: This is identical to my method I posted in the question so essentially it should have worked. Though jQuery may have changed over the last 3 years. Most likely was a problem with functions being called.

这篇关于如何使用jQuery。当.done的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆