JavaScript:Internet Explorer不支持forEach方法
我使用的是gzip算法的javascript实现,它可以很好地与Firefox和Chrome配合使用。但使用Internet Explorer时,我出现以下错误: 不支持forEach方法 代码:JavaScript:Internet Explorer不支持forEach方法,javascript,internet-explorer,foreach,Javascript,Internet Explorer,Foreach,我使用的是gzip算法的javascript实现,它可以很好地与Firefox和Chrome配合使用。但使用Internet Explorer时,我出现以下错误: 不支持forEach方法 代码: deflate.deflate(data, level).forEach(function (byte) { putByte(byte, out); }); 我正在使用InternetExplorer9,它应该支持forEach方法 有什么想法吗 多谢各位 您可以尝试为不支持foreach方
deflate.deflate(data, level).forEach(function (byte) {
putByte(byte, out);
});
我正在使用InternetExplorer9,它应该支持forEach方法
有什么想法吗
多谢各位 您可以尝试为不支持
foreach
方法的浏览器扩展Array
对象,如下所示
一个例子是:
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(fn, scope) {
for(var i = 0, len = this.length; i < len; ++i) {
fn.call(scope, this[i], i, this);
}
}
}
if(!Array.prototype.forEach){
Array.prototype.forEach=函数(fn,范围){
对于(变量i=0,len=this.length;i
IE9不支持forEach,您可以尝试使用jquery。例:
IE8中不支持forEach。然而,IE9应该支持它。你的页面在IE中是否以怪癖模式运行?(可能是偶然?
.forEach()
仅在标准模式下受支持。deflate.deflate()
是否总是返回一个数组?与扩展内置对象不同,您可以将forEach
部分替换为两行for
循环。我希望避免使用jquery。我使用jquery作为解决方法,并对结果感到满意。$。电子邮件,函数(索引,值){$('#lblEmails').append(value+“”);};仅仅为了实现for循环而添加一个完整的库并增加页面加载时间是不好的。
$. each (function (byte) {
putByte(byte, out);
});