jquery delay between javascript functions

巧了我就是萌 提交于 2019-12-02 13:22:11

I would just use a simple timeout:

f1("one", false);
setTimeout(function() { f2("one", false); }, 1000);
$.delay(1000).click(function(){f1('One',false);}).delay(1000).click(function(){f2('One',false);});

not sure what the click is for though ...

if you want to delay a function call then a much simpler way is to use setTimeout().

eg: // calling it in a nested setTimeout for sequential delayed execution setTimeout(function(){

 f1('One',false);
  setTimeout(function(){
    f1('One',false)
  },300)
},300)
function fn1()
{
    alert(1);
}
function fn2()
{
    alert(2);
}
var arr=[fn1,fn2];
var len=arr.length;
var time=1000;
for(var k=0;k<len;k++)
{
    (function(k)
    {
        setTimeout(arr[k],time);
    }(k))
    time=time*2;
}

It executes after a delay of 1 second! DEMO

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!