关于 ie8不兼容的一些方法
生活随笔
收集整理的這篇文章主要介紹了
关于 ie8不兼容的一些方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ie8 不兼容的方法?
?
$(function(){//添加數組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;};}//getOwnPropertyNames keys 方法if(!Object.getOwnPropertyNames || !Object.keys){Object.keys = Object.getOwnPropertyNames = function(temp){var A = [];for(var key in temp){A.push(key);}return A;}}//forEach 方法if ( !Array.prototype.forEach ) { Array.prototype.forEach = function forEach( callback, thisArg ) { var T, k; if ( this == null ) { throw new TypeError( "this is null or not defined" ); } var O = Object(this); var len = O.length >>> 0; if ( typeof callback !== "function" ) { throw new TypeError( callback + " is not a function" ); } if ( arguments.length > 1 ) { T = thisArg; } k = 0; while( k < len ) { var kValue; if ( k in O ) { kValue = O[ k ]; callback.call( T, kValue, k, O ); } k++; } }; } //filter 方法if (!Array.prototype.filter){Array.prototype.filter = function(fun /*, thisArg */){"use strict";if (this === void 0 || this === null)throw new TypeError();var t = Object(this);var len = t.length >>> 0;if (typeof fun !== "function")throw new TypeError();var res = [];var thisArg = arguments.length >= 2 ? arguments[1] : void 0;for (var i = 0; i < len; i++){if (i in t){var val = t[i];// NOTE: Technically this should Object.defineProperty at// the next index, as push can be affected by// properties on Object.prototype and Array.prototype.// But that method's new, and collisions should be// rare, so use the more-compatible alternative.if (fun.call(thisArg, val, i, t))res.push(val);}}return res;};} })?
轉載于:https://www.cnblogs.com/xianhuiwang/p/7943263.html
總結
以上是生活随笔為你收集整理的关于 ie8不兼容的一些方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 翻译:集群索引:通往SQL Server
- 下一篇: 团队作业6——展示博客(Alpha版本)