2013-07-05 108 views
3

IE 7 & 8引發錯誤(通過jQuery的):預期標識符IE8預期標識符錯誤

jQuery(document).ready(function() { 
    jQuery.i18n.properties({ 
        'name': "messages", 
        'path': "/myproject/js/i18n/", 
        'mode': "both", 
        'language': "en", 
        'callback': function() { 
        } 
    }) 
}); 

如果我註釋掉線'path': "/myproject/js/i18n/",錯誤消失,但當然,I18N插件停止工作正常。

感謝您的幫助!

+1

我不知道,但舊的IE並不好混合報價,儘量使用單或雙引號,但不是在同一個語句中都有......或者你只是有一個非打印字符? – Teemu

+0

泰姆,我嘗試了雙引號,並沒有幫助;我會嘗試單引號,但想法! –

+0

泰姆,單引號也沒有幫助。 –

回答

8

在messages.properties文件中有像something.delete.something=something這樣的行。這些內部有'delete'的行導致IE7/8中的jQuery拋出錯誤。我將這些標籤重新命名爲something.dodelete.something,它工作正常。

+0

'刪除'是一個保留字。有關列表,請參閱https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords。一般來說,你也可以做'某事['刪除']。東西' –

+0

它並沒有解釋爲什麼只有IE對它做出這樣的反應。此外,這個詞在標籤內部使用,這是我相信一個字符串。 –

+1

jquery.i18n-properties [generated](https://github.com/jquery-i18n-properties/jquery-i18n-properties/blob/master/jquery.i18n.properties.js#L322)一個JavaScript函數動態地,然後[evals it](https://github.com/jquery-i18n-properties/jquery-i18n-properties/blob/master/jquery.i18n.properties.js#L332)。 IE在該評估中失敗。 –

2

如果您不能重命名,我建議未來:

response.responseJSON.messages.default 

變化

response.responseJSON.messages['default'] 
+0

保留字的好主意。我正在使用IE8的YT-lib。儘管他沒有被try-catch-block執行和保護,但發生了錯誤 –