how to make a sleep in javascript?

后端 未结 9 2050
半阙折子戏
半阙折子戏 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:41

    I Have the Hat has given the right hint. Use the setTimeout method to execute your forth line code after 10 seconds:

    var chkResult = Validation();
    var timeout = window.setTimeout(function() {
        document.getElementById('abc').innerHTML = chkResult;
    }, 10000);
    

    Storing the timeout ID in a variable can be handy if you want to clear a timeout.

提交回复
热议问题