2011-11-21 34 views
19

我在jQuery的這個sniplet代碼無用的方法setTimeout(失蹤各地參數報價?)

$element.parent().children().last().hide().show('slide', {direction : 'left'}, 700, function() { 
    $element.delay(2000, function() { 
     $element.parent().children().last().hide('slide', {direction: 'left'}, 700);    
     reload_table(question_number); 
     //delay ends here 
    }); 
}); 

delay聲明爲:

jQuery.fn.delay = function(time,func){ 
    return this.each(function(){ 
     setTimeout(func,time); 
    }); 
}; 

現在我得到的錯誤:

useless setTimeout call (missing quotes around argument?)

FF3.x,Firefox 6+可以。有關於此的任何想法?爲什麼會發生這種情況?

回答

7

已經存在一個jQuery方法delay,它期望一個字符串(queueName)而不是一個函數作爲參數。 爲延遲方法選擇另一個名稱以避免衝突。

+0

對不起,說,但沒有修復它 – kosta5

+16

爲什麼這是公認的答案,如果這沒有解決它? –

+2

這是一個謎... – Tebe

-2

的問題是在Firefox 3。它不處理某些元素正確=>元素在樹完全忽略和忽視 - >因此,我原來的問題

+5

非常無益和不具說服力的答案。 – Cyprus106

7

僅供參考,如果有人絆倒在這個問題,是尋找可能的答案。我得到了與第一張海報完全相同的錯誤信息,因爲我混合了參數順序setTimeout

此:

setTimeout(25, function(){ 
    spotlight.intro.find('#intro').ellipsis(); 
}); 

...給我的錯誤信息。我改變了功能,以這樣的:

setTimeout(function(){ 
    spotlight.intro.find('#intro').ellipsis(); 
}, 25); 

我的問題得到解決。

17

我得到了同樣的錯誤,當我寫

setTimeout(updateStatus(), 5000); 

,而不是

setTimeout(updateStatus, 5000); 
+0

OP已經正確調用了該方法!這不是問題。他已經在第一個參數中傳遞了一個指向函數的指針。 – gcb

10

我wsbaser同意。我具有將信息傳遞給該函數所需的額外實例,併爲簡化起見使用:

setTimeout(function(){ updateStatus(myData) } , 5000); 

的參數需要是一個函數,而不是一個函數被調用。 Firefox發現了這個錯誤,Chrome讓它走了。