javascript - 为什么我的 Javascript 在 IE8 中无法运行?

标签 javascript jquery internet-explorer-8

以下代码在 IE8 中中断:

getTypes: function (filter) {
    features = []
    _.each(this.collection.models, function (item) {
        _.each(item.get(filter), function (value) {
            if(features.indexOf(value) == -1){ //// error happens here
                features.push(value)
            }
        })
    })
    return features
}

我收到错误信息: 消息:对象不支持此属性或方法

http://jsfiddle.net/w8fm2bf1/

这是为什么?

最佳答案

IE9之前的IE版本不支持.indexOf() function for Array

作为替代方案,您可以使用 jQuery.inArray() .像这样:

if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(val) {
        return jQuery.inArray(val, this);
    };
}

关于javascript - 为什么我的 Javascript 在 IE8 中无法运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29893208/

相关文章:

c++ - 以编程方式在 IE 中设置页面缩放和文本大小

javascript - 如何让 AngularJS 应用程序在 IE8 中运行?

javascript - 无法读取 null 的属性 'indexOf'

javascript - 如何处理 "Go"/"Enter"keyboard button Ionic2 <ion-input>

javascript - 使用 D3 转换禁用 SVG 上的悬停 CSS

javascript - JS syntaxError - chrome - 数组解构

页面部分加载时 Javascript 访问被拒绝错误 - 为什么?

jquery - 监听本地存储更改事件

c# - 我如何 [简单地] 在业务线 Web 应用程序中使用 JSON 数据

javascript - 即 8 : move caret to the end of a text input field AND make the end visible