how to make a sleep in javascript?

后端 未结 9 1977
半阙折子戏
半阙折子戏 2020-12-20 23:00

Does anyone know how can I make a sleep in javascript before next line been read by the system?

example:

    1 var chkResult = Validation();
    2 /         


        
相关标签:
9条回答
  • 2020-12-20 23:43

    The delay won't happen until JavaScript has relinquished control back to the browser, so your line 4 will execute before the setTimeout starts.

    You should be making everything happen based on events.

    0 讨论(0)
  • 2020-12-20 23:48

    but this way, your line line will execute BEFORE line 4

    0 讨论(0)
  • 2020-12-20 23:55

    setTimeout starts a separate execution "thread" within the JavaScript interpreter. You need to pass it a function and design your scripts in such a way that the function the setTimeout runs will continue where the calling function left off--thereby simulating a sleep.

    0 讨论(0)
提交回复
热议问题