<分区>
我想强制一个函数等待 1 秒,然后她在 javascript 中继续执行该操作。 例如:
function DoSomething(){
// wait 1 second
//continue w.e is this function does.
}
谢谢。
标签 javascript sleep
<分区>
我想强制一个函数等待 1 秒,然后她在 javascript 中继续执行该操作。 例如:
function DoSomething(){
// wait 1 second
//continue w.e is this function does.
}
谢谢。
最佳答案
如果我没理解错的话,你需要这个:
setTimeout(DoSomething ,1000);
编辑 ,感谢 Teemu :
function DoSomething (){
setTimeout(ContinueDoSomething ,1000);
}
function ContinueDoSomething (){
// ...
}
还有一种方法在某些情况下可能最有效:
function DoSomething (){
setTimeout( function(){
// ...
},1000);
}
关于javascript - 在javascript中强制等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17041897/
相关文章:
javascript - 如果 href 等于,jquery 隐藏元素
javascript - 如何读取 js-year-calendar 库(无法读取 null 的属性 'classList')
python - docker 在 python 循环中执行 time.sleep(1) 时卡住
javascript - jQuery 获取容器中内容的高度
javascript - 比较angularjs指令中的两个字段
javascript - 返回与 jQuery 连接的动态字符串