首页 > 编程知识 正文

ie9兼容性设置在哪里,ie8如何升级至ie11

时间:2023-05-04 09:10:08 阅读:28374 作者:2476

数组循环数组循环的本机forEach方法IE9开始受支持。 因为这是一种相对常见且容易忽略兼容性问题的方法,所以它处理在代码中使用forEach循环处理数组的操作。 可以用原始for循环或jQuery中的$.each ()替换。 公共js建议扩展阵列属性。 代码如下。

if (! array.prototype.foreach (array.prototype.foreach=function foreach (callback,thisArg ) { var T,k; if(this==null ) thrownewtypeerror ) (thisisnullornotdefined ); }varo=object(this ); var len=O.length 0; If (电话呼叫类型!==' function ' (throw new typeerror (callback ' is nota function ' ); (if ) arguments.length1) { T=thisArg; } k=0; wile(klen ) { var kValue; if(kino ) { kValue=O[ k ]; callback.call(t,kValue,k,o ); (k; }; } 字符查询

的本机indexOf方法IE9已开始支持。 兼容代码如下:

if (! array.prototype.index of (array.prototype.index of=function (ELT/*,from*/) { var len=this.length 0; varfrom=number(arguments[1]||0; from=(from0? math.ceil(from ) :math.floor ) from; if(from0) from =len; for (; 来自len; from () frominthisthis[from]===ELT ) return from; }返回- 1; (; }现在支持} 数组循环数组循环的本机map方法IE9。 在代码的全局搜索中,很久没有找到使用map方法循环数组的内容,但建议您也添加兼容代码。 也请注意之后的使用。 兼容代码如下:

if (! array.prototype.map (array.prototype.map=function ) callback,thisArg ) { var T,a,k; if(this==null ) thrownewtypeerror ) (thisisnullornotdefined ); }varo=object(this ); var len=O.length 0; If (电话呼叫类型!==' function ' (throw new typeerror (callback ' is nota function ' ); (if ) thisarg ) { T=thisArg; }a=newArray(Len ); k=0; while(klen ) { var kValue,映射值; if(kino ) { kValue=O[k]; mappedvalue=callback.call(t,kValue,k,o ); a [ k ]=映射值; (k; }返回a; (; }在array.splice (索引,长度) chrome中,长度的默认值最大,在IE8中,长度的默认值为0。 使用splice方法操作数组的与IE8兼容。 这需要根据具体的业务代码实现场景进行分析。 主要检查第二个length参数是否为缺省参数。 代码全局搜索找不到第二个参数的默认用法,但也需要注意后续使用。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。