2012-05-29 140 views
0

IE7模式下,我在IE9中收到以下错误。使用小的计数脚本:奇怪的IE7怪癖

SCRIPT1028:预期标识符,字符串或数字

代码

$.fn.countTo.defaults = { 
    from: 0, // the number the element should start at 
    to: 100, // the number the element should end at 
    speed: 1000, // how long it should take to count between the target numbers 
    refreshInterval: 100, // how often the element should be updated 
    decimals: 2, // the number of decimal places to show 
    onUpdate: null, // callback method for every time the element is updated, 
    onComplete: null, // callback method for when the element finishes updating 
}; 

185线是最后的方括号和分号

我们需要这个在IE7中工作,但是这个错误正在破坏脚本。

+2

我真的建议不使用浏览器兼容模式来测试IE浏览器。这些模式几乎但不完全不同于它们的真实柜台部分。以下是用于测试多个IE版本的Microsofts Virtual PC的链接:http://www.microsoft.com/en-us/download/details.aspx?id=11575 – JaredMcAteer

+0

+1 to @ JaredMcAteer的评论。在帖子标题二中加上三个字是多余的。 –

+0

[预期的标识符或字符串在JavaScript中]的可能重复(http://stackoverflow.com/questions/4930960/expected-identifier-or-string-in-javascript)这是在搜索中输入错误消息时的最高结果框。 http://stackoverflow.com/search?q=Expected+identifier%2C+string+or+number – 2012-05-29 21:16:40

回答

8

删除onComplete后的尾随逗号。

+0

优秀,谢谢多多 – absentx

5
$.fn.countTo.defaults = { 
    from: 0, // the number the element should start at 
    to: 100, // the number the element should end at 
    speed: 1000, // how long it should take to count between the target numbers 
    refreshInterval: 100, // how often the element should be updated 
    decimals: 2, // the number of decimal places to show 
    onUpdate: null, // callback method for every time the element is updated, 
    onComplete: null // callback method for when the element finishes updating 
}; 

onComplete: null

2

问题是与您的默认值的最终值的最后一个逗号删除逗号。 IE有这个问题。让它像这样,你应该很好:

$.fn.countTo.defaults = { 
    from: 0, // the number the element should start at 
    to: 100, // the number the element should end at 
    speed: 1000, // how long it should take to count between the target numbers 
    refreshInterval: 100, // how often the element should be updated 
    decimals: 2, // the number of decimal places to show 
    onUpdate: null, // callback method for every time the element is updated, 
    onComplete: null // callback method for when the element finishes updating 
};