为什么这段代码会出错?

时间:2010-06-01 13:30:44

标签: javascript jquery

$("#main").animate({ 
display: "block",
width: "70%",
opacity: 0.4,
marginLeft: "0.6in",
fontSize: "3em", 
borderWidth: "10px"
} 1500);

这是jQuery。我在争论列表“消息后得到了”缺失。怎么了?

3 个答案:

答案 0 :(得分:6)

UMM

} 1500);

在1500之前缺少逗号

我建议将来使用http://www.jslint.com/吗?如果您粘贴在那里的代码块中,您将收到以下错误:

Error:
Problem at line 8 character 3: Expected ')' and instead saw '1500'.

} 1500);

Problem at line 8 character 7: Missing semicolon.

} 1500);

Problem at line 8 character 7: Expected an identifier and instead saw ')'.

} 1500);

Problem at line 8 character 7: Stopping, unable to continue. (100% scanned).

Implied global: $ 1

之后,很容易看出你的错误必须在第8行。

答案 1 :(得分:3)

您需要在结尾的持续时间之前使用逗号(目前为} 1500);),如下所示:

$("#main").animate({ 
display: "block",
width: "70%",
opacity: 0.4,
marginLeft: "0.6in",
fontSize: "3em", 
borderWidth: "10px"
}, 1500);

答案 2 :(得分:3)

$("#main").animate({ 
display: "block",
width: "70%",
opacity: 0.4,
marginLeft: "0.6in",
fontSize: "3em", 
borderWidth: "10px"
}, 1500); // you have forgotten the comma here...