2011-08-16 37 views
0

jQuery 1.3中的.delay()函數有替代嗎?我知道在jQuery 1.4中,你可以簡單地使用.delay()函數來延遲函數發生X秒的時間,但是在某些情況下,我可以做同樣的事情,但在1.3中?替代jQuery 1.3的.delay()函數並製作jQuery循環?

另外我需要在jQuery中創建一個循環函數,所以在函數執行完成後,它會再次執行。有沒有可能的方式在jQuery 1.3中做到這一點?

我被困在jQuery 1.3和我的困境中,我無法更新到1.4所以請不要回答告訴我更新,除非這是我唯一的選擇。謝謝。

回答

1

我不明白你的問題,但setTimeout函數不能解決?

function delay() 
{ 
    setTimeout("Func1()", 3000); 
} 
1

您可以通過添加從jQuery 1.4+源拷貝功能到您的代碼下面給你的腳本:

// the direct source of the delay function in 1.4+ 
jQuery.fn.extend({ 
    delay: function(time, type) { 
     time = jQuery.fx ? jQuery.fx.speeds[time] || time : time; 
     type = type || "fx"; 

     return this.queue(type, function() { 
      var elem = this; 
      setTimeout(function() { 
       jQuery.dequeue(elem, type); 
      }, time); 
     }); 
    } 
}); 

然後正常調用.delay功能。

+0

這對我的作品!感謝你... –

0

我也經歷過這個問題,我建議你使用javascript本身的setTimeOut函數。這不是一個更好的選擇,但它也很好。

For循環功能 編寫一個函數,例如

function runThisAgainAndAgain(){ 
    call this same function in setTimeout here.... 
}