why settimeout not delay the function execution?

后端 未结 2 715
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-11 21:20
function tryToDownload(url)
{

       oIFrm = document.getElementById(\'myIFrm\');
       oIFrm.src = url;
      // alert(url);
      // url=escape(url);

      setT         


        
2条回答
  •  生来不讨喜
    2021-01-11 21:54

    That's because you are calling the function, and using the return value in the setTimeout call. Wrap it in an anonymous function so that it's called by setTimeout:

    function tryToDownload(url) {
    
        oIFrm = document.getElementById('myIFrm');
        oIFrm.src = url;
       // alert(url);
       // url=escape(url);
    
       setTimeout(function() { deletefile(url); }, 25000);
    
    }
    

提交回复
热议问题