gpt4 book ai didi

jquery $.when() .then() 和 .done() 之间的区别

转载 作者:行者123 更新时间:2023-12-03 21:34:57 24 4
gpt4 key购买 nike

我试图理解两者之间的区别

$.when(...).then(...)

$.when(...).done(...)

在 jQuery 中。据我了解,它们都是在内部对象完成加载时执行的。但有什么区别呢。示例将非常感激。

最佳答案

.done() 只有成功回调。

.then() 有成功和失败回调。

As of jQuery 1.8, the deferred.then() method returns a new promise that can filter the status and values of a deferred through a function, replacing the now-deprecated deferred.pipe() method.

The deferred.done() method accepts one or more arguments, all of which can be either a single function or an array of functions.

Since deferred.done() returns the deferred object, other methods of the deferred object can be chained to this one, including additional .done() methods. When the Deferred is resolved, doneCallbacks are executed using the arguments provided to the resolve or resolveWith method call in the order they were added.

关于jquery $.when() .then() 和 .done() 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14259203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com