Execute script after specific delay using JavaScript

前端 未结 15 2017
陌清茗
陌清茗 2020-11-22 12:29

Is there any JavaScript method similar to the jQuery delay() or wait() (to delay the execution of a script for a specific amount of time)?

15条回答
  •  臣服心动
    2020-11-22 12:44

    Just to expand a little... You can execute code directly in the setTimeout call, but as @patrick says, you normally assign a callback function, like this. The time is milliseconds

    setTimeout(func, 4000);
    function func() {
        alert('Do stuff here');
    }
    

提交回复
热议问题