javascript - 在javascript中强制等待

标签 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')

iOS 进入深度 sleep 需要多长时间?

python - docker 在 python 循环中执行 time.sleep(1) 时卡住

java - 检测手机 hibernate 时的手势

javascript - jQuery 获取容器中内容的高度

javascript - 比较angularjs指令中的两个字段

javascript - 返回与 jQuery 连接的动态字符串

events - Win 8 Metro 模式 : WaitForSingleObjectEx failed

windows - powershell 鼠标移动不会阻止空闲模式