gpt4 book ai didi

jQuery 延迟

转载 作者:行者123 更新时间:2023-12-01 02:46:52 27 4
gpt4 key购买 nike

我是 jquery deferreds 的新手。这里我有一个简单的example

谁能告诉我为什么在其他函数完成之前就触发完成函数(“现在是我的时间”)?

这里的人 example还创建一个延迟对象并返回一个 promise ,我也是如此。
我必须如何更改我的小示例才能仅在 6 秒后(超时后)触发完成函数?

提前非常感谢
沃尔夫冈

最佳答案

您应该将函数传递给 done()方法,而是立即调用 console.log() 并将其返回值传递给 done()。你应该写:

$.when(test()).done(function() {
console.log("now it's my time");
});

而不是:

$.when(test()).done(console.log("now it's my time"));

您会发现更新的 fiddle here .

关于jQuery 延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9381027/

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