indexOf throwing error in IE8, I am using knockoutjs

This question already has an answer here:

  • Why doesn't indexOf work on an array IE8? 7 answers

  • Try this

        return checkedPriceVals.toString()
    .indexOf(priceObjects[i].fields.displayable.value())>=0;
    

    it will work.


    使用$ .inArray代替indexOf,或者你可以定义方法:

    if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function (obj, start) {
        for (var i = (start || 0), j = this.length; i < j; i++) {
            if (this[i] === obj) { return i; }
        }
        return -1;
    }
    }
    
    链接地址: http://www.djcxy.com/p/18960.html

    上一篇: 如何使它工作

    下一篇: indexOf在IE8中抛出错误,我正在使用knockoutjs