IE11中的JavaScript给我脚本错误1003 [英] JavaScript in IE11 giving me script error 1003
问题描述
我有一个带有手风琴和一些JavaScript的网站.在Firefox中,一切正常运行,但是在IE11中,我得到了错误
I have a site with an accordion and some javascript. In Firefox everything is working as it should, but in IE11 I get the error
SCRIPT1003:预期为:"
SCRIPT1003: Expected ':'
我将其范围缩小到了我的.js文件中的这段代码:
I narrowed it down to this piece of code in my .js file:
var nmArray = new Array();
function saveplayers() {
var x;
for (x=0;x<32;x++) {
var y = "i"+eval(x+1);
nmArray[x]=document.getElementById(y).value;
}
var request = $.ajax({
type: "POST",
url: "savep.php",
data: ({ nmArray }),
cache: false
});
}
错误提示在({ nmAray })
如果我取消使用此功能,则我的站点将再次运行.为了调试,我剥离了HTML,甚至没有调用此函数.我只包含了.js文件.
If I take this function out, my site works again. For debugging I stripped down my HTML, and I'm not even calling this function. I just included the .js file.
推荐答案
在支持ES6的浏览器中,语法({nmArray})
是{nmArray: nmArray}
的快捷方式. IE11不支持此功能(基于收到的错误),因此您必须将其重写为:
The syntax ({nmArray})
in a browser that supports ES6 is a shortcut for {nmArray: nmArray}
. IE11 doesn't support this feature (based on the error you're receiving), so you'll have to rewrite it as:
data: ({ nmArray: nmArray }),
请注意,在这种情况下,您可以省略包装()
note that in this case you can omit the wrapping ()
data: { nmArray: nmArray },
这篇关于IE11中的JavaScript给我脚本错误1003的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!