1、为Array原型添加indexOf方法(如果学过面向对象,相当于给Array类添加实例方法),方法体如下:

//添加数组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;
};
}

2、使用jQuery的inArray方法,注:jQuery版本2.0以上不再支持IE8

var arr = [ 1, "2", false, "aaa" ];
jQuery.inArray("aaa", arr);
jQuery.inArray(false, arr);
jQuery.inArray("2", arr);
jQuery.inArray(1, arr, 2);

不存在就为-1;

IE8下不识别indexOf的问题的更多相关文章

  1. IE8下服务端获取客户端文件的路径为C:/fakePath问题的解决方案

    上一篇文章上提到,IE8下服务端获取客户端文件的路径时,会变成C:/fakePath问题,于是乎通过文件路径去获得文件大小就失败了. 上网搜了一下,主要原因是IE8因为安全考虑,在上传文件时屏蔽了真实 ...

  2. ie8下使用knockoutjs遇到的一个模板异常

    ViewModel中有一个数组,代码大概如下: function ReportViewModel(){ var self = this; self.extendedProperties = ko.ob ...

  3. input 的 placeholder属性在IE8下的兼容处理

    placeholder是input标签的新属性,在使用的时候有两个问题: 1.IE8 下不兼容 处理思路: 如果浏览器不识别placeholder属性,给input添加类名placeholder,模仿 ...

  4. ueditor1.4.3 在IE8下的 BUG

    ueditor1.4.3  .net 版 在IE8 下,多图片上传完成后,点击确认时报错,无法插入图片到编辑器中 原因是 ueditor.all.js 中的 24835 行 if (whitList[ ...

  5. IE8下导入EXCEL数据传到客户端以附件下载

    IE8下导入EXCEL数据传到客户端以附件下载方式出现,而不显示数据,解决方法:以text/html格式返回. HttpResponseMessage message = new HttpRespon ...

  6. 真~让IE8支持background: rbga; ,IE8下兼容rgba颜色的半透明背景

    IE8下兼容rgba颜色的半透明背景 这样的标题在百度和google搜索下很多篇文章,讲解IE8下兼容rgba的. 这些文章全部都是使用IE下的filter来使元素透明,但是这个里面会有bug. 它们 ...

  7. echarts在IE8下遮挡其他组件的问题

    echarts的图在IE8下会浮在上层遮挡住其他组件,解决方式是页面中引入 <meta http-equiv="X-UA-Compatible" content=" ...

  8. jquery.validate.js在IE8下报错不运行

    因为项目要表单验证,所以特意去找了jquery.validate这个应该是jquery官方团队出品的表单验证插件. 实际应用时,却在IE8调试时碰到了问题. 从jquery.validate官网下载了 ...

  9. ie8下背景图片平铺问题

    IE9+及其他浏览器实现背景图片平铺可能需要一个属性就可以background-size:100%/cover; 但是ie8下background-size是不兼容的,因此我们需要用到滤镜,来解决背景 ...

随机推荐

  1. 在Word 中撰写并发布到博客的帮助

    目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...

  2. StarUML 5.0问题解决:Failed to open the model file. Invalid file format.

    使用StarUML 5.0打开一个已有的文件时,如果遇到报"Failed to open the model file. Invalid file format."错误,则原因可能 ...

  3. CSS实现图片阴影效果

    <title>无标题文档</title> <style type="text/css"> /*方法一:使用一个GIF文件的方法*/ .gifsh ...

  4. Spring源码解析 - BeanFactory

    BeanFactory是Spring实现依赖注入的核心接口.提供应用的统一配置注册功能,实现业务开发解偶.使用getBean可以代替单例,原型设计模式. 顶重要的BeanFactory里注释写得太好了 ...

  5. 20169221 2016-2017-2《移动平台与android开发》学习总结

    每周作业连接汇总 第一周<Intellj IDEA 简易教程>学习,码云的基础使用.由于第一次写作业,网络攻防作业占据了我整个周四周五周六的时间这周java时间被挤没了,所以没有完成所有学 ...

  6. ZOJ3704 I am Nexus Master! 2017-04-06 23:36 56人阅读 评论(0) 收藏

    I am Nexus Master! Time Limit: 2 Seconds      Memory Limit: 65536 KB NexusHD.org is a popular PT (Pr ...

  7. The J-Link hardware debugging Eclipse plug-in

    Quicklinks If you already know what are the features of the new plug-in and just want to know how to ...

  8. C# Aes CryptoStream Specified padding mode is not valid for this algorithm的解決方法

    //解密數據            using (var ss = File.OpenRead(@"d:\qq.d.flac"))            {             ...

  9. linux gitlab-ctl reconfigure报错问题修复 502

    Running handlers: There was an error running gitlab-ctl reconfigure: bash[migrate gitlab-rails datab ...

  10. 使用google chrome抓取数据:抓取全国的高中的数据

    http://tomycat.github.io/blog/other/2014/05/28/use-google-chrome-capture-data.html