在元素列表[object Object]之后的SyntaxError:missing] [英] SyntaxError: missing ] after element list [object Object]
问题描述
我在firebug中遇到了这个错误:
I got this error in firebug :
SyntaxError: missing ] after element list
[object Object]
以下javascript代码:
for the following javascript piece of code :
for ( var i = 0; i < 4; i++ ) {
setTimeout( function(){
closeBtn( i,'.lt400' );
// the error exactly happened in next line:
setTimeout($('#uploaded-holder').hide(), i * 300 );
}, i * 300 );
}
我不知道如何在那里失踪...方式,在Chrome中我收到此错误:
I don't know how a ] can be missing there.. by the way, in chrome i got this error :
Uncaught SyntaxError: Unexpected identifier
推荐答案
setTimeout
需要一个函数或一串代码作为第一个参数。您正在传递此表达式的评估结果:
setTimeout
expects a function or a string of code as the first parameter. You are passing the result of the evaluation of this expression:
$('#uploaded-holder').hide()
此表达式既不返回字符串,也不返回函数。它返回一个jQuery集合。
This expression returns neither a string, nor a function. It returns a jQuery collection.
你想:
setTimeout(function () {
$('#uploaded-holder').hide();
}, i * 300 );
但是,由于setTimeouts和循环的组合,你有一组奇怪的代码。一旦这个错误得到解决,我预计会有一些奇怪的怪异。例如, i
不会出现在执行许多内部函数时的预期...
You have an odd set of code there, though, given the combination of setTimeouts and the loop. I would expect some wild oddities to come from it once this error is resolved. For example, i
is not going to be what you expect in the execution of many of those internal functions...
这篇关于在元素列表[object Object]之后的SyntaxError:missing]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!