gpt4 book ai didi

javascript - setTimeout 完成后运行下一个函数

转载 作者:可可西里 更新时间:2023-11-01 02:16:48 26 4
gpt4 key购买 nike

如何让它发挥作用?请帮忙。

function first() {
setTimeout((function() {
$('#q').append('first <br>');
}), 1000);
}
function second() {
$('#q').append('second <br>');
}
function third() {
$('#q').append('third <br>');
}
$.when(first()).done(second()).done(third());

first() 作为最后一个函数运行,我需要作为第一个

在这里 fiddle :JSFIDDLE

最佳答案

我不确定你为什么要这样做,但如果你想同步执行它们,你可以将第二个和第三个函数调用放在 setTimeout 中:

function first() {
setTimeout(function() {
$('#q').append('first <br>');
second();
third();
}, 1000);
}
function second() {
$('#q').append('second <br>');
}
function third() {
$('#q').append('third <br>');
}
first();

关于javascript - setTimeout 完成后运行下一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30364849/

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