IE8不支持数组的indexOf方法
在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方法的更多相关文章
- 终于解决了IE8不支持数组的indexOf方法,array的IndexOf方法
/* 终于解决了IE8不支持数组的indexOf方法 */ if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (el ...
- IE8不支持数组的indexOf方法 如何解决
转自:http://www.jbxue.com/article/8367.html 原因分析: 这是一个js bug, 在IE8下,js数组没有indexOf方法,会报错:而在其它浏览器下(Firef ...
- 解决了IE8不支持数组的indexOf方法
ie在过去给我们添了很多坑. if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/ ) { ...
- js解决IE不支持数组的indexOf()方法
if (!Array.indexOf) { Array.indexOf = function (obj) { ...
- JavaScript——数组的indexOf()方法在IE8中的兼容性问题
昨天在工作中遇到一个问题:数组的indexOf()方法在IE8中无效. 如以下代码在IE8中报错“对象不支持“indexOf”属性或方法”: var arr = [1,2,3]; var index ...
- JavaScript—从数组的indexOf方法深入——Object的Property机制。
在js中,可以说万物皆对象(object),一个数组也是一个对象(array). 很多对象都有很多很方便的方法 比如数组的push,concat,slice等等,但是如果一些对象,它没有实现这些方法, ...
- js 判断数组包含某值的方法 和 javascript数组扩展indexOf()方法
var questionId = []; var anSwerIdValue = []; ////javascript数组扩展indexOf()方法 Array.prototype.indexOf ...
- 数组的indexOf方法--数组去重
数组的indexOf方法 数组方法大家再熟悉不过了,却忽略了数组有 indexOf 这个方法(我个人感觉). 干说不练瞎扯淡,遇到了什么问题,注意⚠️点又在哪里? let arr = ['orange ...
- Javascript中的数组去重-indexof方法
在Javascript中,有时我们会用到数组去重.我在这里给大家介绍一下本人认为最简单实用的一种方法-indexOf()去重. var arr = [1,1,1,2,2,2,3,3,4,5,6,2,1 ...
随机推荐
- 【Linux技术】linux之configure,pkg-config和PKG_CONFIG_PATH
linux之configure,pkg-config和PKG_CONFIG_PATH 1.初衷 1)前面在装gtk时冒出来一个pkg-config,当时虽然不大清楚它是个什么东西,不过大致了解了下它的 ...
- vue实现点击区域外部的区域,关闭该区域
var _this = this; document.addEventListener('click',function(e){ console.log(_this.$refs.configforms ...
- Java中的异常处理:何时抛出异常,何时捕获异常,何时处理异常?
Java中的异常处理:何时抛出异常,何时捕获异常? 2017-06-07 1 异常分类 Throwable对象可以分为两组: 一组是unchecked异常,异常处理机制往往不用于这组异常,包括: Er ...
- Python实现归并排序
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/3/18 14:26 # @Author : baoshan # @Site ...
- python 字符串格式化转换类型
- JAVA-JSP内置对象之response对象实现页面自动跳转
相关资料:<21天学通Java Web开发> response对象 实现页面自动跳转1.可以通过response对象的addHeader()方法添加一个标题为Refresh的标头,并指定页 ...
- 未能加载文件或程序集“System.Web.Mvc, Version=3.0.0.0,
直接下载安装 ASP.NET MVC 3.0就可以了
- C语言 · 新生舞会
算法训练 新生舞会 时间限制:1.0s 内存限制:512.0MB 问题描述 新生舞会开始了.n名新生每人有三个属性:姓名.学号.性别.其中,姓名用长度不超过20的仅由大小写字母构成的 ...
- 【oneday_onepage】——Growth Is A Bitch
Companies are worth a multiple of their earnings and that multiple is directly related to earnings g ...
- WebForm发送邮件
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Ne ...