javascript sleep with SetTimeout

前端 未结 6 2070
粉色の甜心
粉色の甜心 2020-12-21 18:34

I\'m trying to send emails with a 10 seconds delay between. I wrote this code:

$(document).ready(function() {
    for (i = 0; i < 20; i++) {
        setTi         


        
6条回答
  •  悲&欢浪女
    2020-12-21 19:23

    You should create a function which calls itself after 5 seconds

    var i=0;
    
    function sendEmailNow() {
         SendEmail(i);
         ++i;
       if(i<20) {
            setTimeout(sendEmailNow, 5000);
        }
    }
    

提交回复
热议问题