在IE8下有个js错误,但是在其它浏览器下(Firefox, Chrome, IE9)下面都很正常。后来调试发现原因是在IE8下,js数组没有indexOf方法。

在使用indexOf方法前,执行一下下面的js, 原理就是如果发现数组没有indexOf方法,会添加上这个方法

 

if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;
for (; from < len; from++)
{
if (from in this &&
this[from] === elt)
return from;
}
return -1;
};
}

IE8不支持数组的indexOf方法的更多相关文章

  1. 终于解决了IE8不支持数组的indexOf方法,array的IndexOf方法

    /* 终于解决了IE8不支持数组的indexOf方法 */ if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (el ...

  2. IE8不支持数组的indexOf方法 如何解决

    转自:http://www.jbxue.com/article/8367.html 原因分析: 这是一个js bug, 在IE8下,js数组没有indexOf方法,会报错:而在其它浏览器下(Firef ...

  3. 解决了IE8不支持数组的indexOf方法

    ie在过去给我们添了很多坑. if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/ ) { ...

  4. js解决IE不支持数组的indexOf()方法

    if (!Array.indexOf) {                                    Array.indexOf = function (obj) {            ...

  5. JavaScript——数组的indexOf()方法在IE8中的兼容性问题

    昨天在工作中遇到一个问题:数组的indexOf()方法在IE8中无效. 如以下代码在IE8中报错“对象不支持“indexOf”属性或方法”: var arr = [1,2,3]; var index ...

  6. JavaScript—从数组的indexOf方法深入——Object的Property机制。

    在js中,可以说万物皆对象(object),一个数组也是一个对象(array). 很多对象都有很多很方便的方法 比如数组的push,concat,slice等等,但是如果一些对象,它没有实现这些方法, ...

  7. js 判断数组包含某值的方法 和 javascript数组扩展indexOf()方法

    var  questionId = []; var anSwerIdValue = []; ////javascript数组扩展indexOf()方法 Array.prototype.indexOf ...

  8. 数组的indexOf方法--数组去重

    数组的indexOf方法 数组方法大家再熟悉不过了,却忽略了数组有 indexOf 这个方法(我个人感觉). 干说不练瞎扯淡,遇到了什么问题,注意⚠️点又在哪里? let arr = ['orange ...

  9. Javascript中的数组去重-indexof方法

    在Javascript中,有时我们会用到数组去重.我在这里给大家介绍一下本人认为最简单实用的一种方法-indexOf()去重. var arr = [1,1,1,2,2,2,3,3,4,5,6,2,1 ...

随机推荐

  1. 一次tomcat配置参数调优Jmeter压力测试记录前后对比

    使用的tomcat版本为:apache-tomcat-7.0.53 使用测试工具Jmeter版本为:apache-jmeter-2.12 1.测试前tomat的"server.xml&quo ...

  2. sbt编译spark程序提示value toDF is not a member of Seq()

    sbt编译spark程序提示value toDF is not a member of Seq() 前提 使用Scala编写的Spark程序,在sbt编译打包的时候提示value toDF is no ...

  3. Ubuntu 系统下卸载 IntelliJ IDEA

    参考:http://blog.csdn.net/csdnones/article/details/50449947 卸载只需要删除解压出来的目录就行了,然后删除/home/你用登录名/IntelliJ ...

  4. LeetCode: Triangle 解题报告

    Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to a ...

  5. spring InitializingBean

    先说总结:1:spring为bean提供了两种初始化bean的方式,实现InitializingBean接口,实现afterPropertiesSet方法,或者在配置文件中同过init-method指 ...

  6. mysql 锁表操作流程

  7. [转]bigdecimal 保留小数位

    原文地址:https://www.cnblogs.com/liqforstudy/p/5652517.html public class test1_format { public static vo ...

  8. [转]oracle在删除表\表空间\用户时,如何释放磁盘空间

    一.drop表 执行drop table xx 语句 drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 通过查询回收站 ...

  9. JAVA读取MongoDB中的二进制图片并在jsp中显示

    http://blog.csdn.net/u012138706/article/details/52180665

  10. PHP写的一个轻量级的DI容器类(转)

    理解什么是Di/IoC,依赖注入/控制反转.两者说的是一个东西,是当下流行的一种设计模式.大致的意思就是,准备一个盒子(容器),事先将项目中可能用到的类扔进去,在项目中直接从容器中拿,也就是避免了直接 ...