Javascript sleep/delay/wait function

后端 未结 6 1205
时光取名叫无心
时光取名叫无心 2021-01-03 23:13

Sorry if this question has already been asked here before, I could not find a suitable answer.

I am wanting to create a JavaScript sleep/delay/wait function that I c

6条回答
  •  鱼传尺愫
    2021-01-04 00:00

    You could use the following code, it does a recursive call into the function in order to properly wait for the desired time.

    function exportar(page,miliseconds,totalpages)
    {
        if (page <= totalpages)
        {
            nextpage = page + 1;
            console.log('fnExcelReport('+ page +'); nextpage = '+ nextpage + '; miliseconds = '+ miliseconds + '; totalpages = '+ totalpages );
            fnExcelReport(page);
            setTimeout(function(){
                exportar(nextpage,miliseconds,totalpages);
            },miliseconds);
        };
    }
    

提交回复
热议问题