奇怪的IE7怪癖

时间:2012-05-29 21:04:38

标签: javascript jquery

我在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中使用此功能,但此错误会破坏脚本。

3 个答案:

答案 0 :(得分:8)

删除onComplete之后的逗号逗号。

答案 1 :(得分: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 :(得分: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
};