gpt4 book ai didi

等待

转载 作者:行者123 更新时间:2023-11-30 11:11:36 28 4
gpt4 key购买 nike

我试图让脚本暂停大约 1 秒,然后继续执行脚本,但我似乎无法弄清楚如何做。这是我的代码:

function hello() {
alert("Hi!")
//I need about a 1 seconed pause here;
alert("Hi again!");
}
<button onclick="hello()">Say Hi!</button>

我已经尝试过以下方法:

function hello() {
alert("Hi!")
setTimeout(myFunction, 3000)//I thought this would wait, run the function, then return to the function hello()...
alert("Hi again!")
}
function myFunction {
a = document.getElementById("blank")
a.innerHTML = "wait complete"
}
<button onclick="hello()">Say Hi!</button>
<div id="blank">
...
</div>

最佳答案

您使用 setTimeout 函数走在正确的轨道上:

function hello() {
alert("Hi!")
setTimeout(function() {
alert("Hi again!");
}, 1000)

}
<button onclick="hello()">Say Hi!</button>

关于等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53403262/

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