2012-05-29 169 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 
};