ArraySlice不能用在DOM集合中,若加if判断心里则又不爽,故写此脚本以修复之
(function(){ /** * fix IE(lte 8) script error of ArraySlice called on HTMLCollection||NodeList */ try{Array.prototype.slice.call(document.forms)}catch(_){ var parseArray=function(obj){ if(obj instanceof Array)return obj; var l=obj.length>>>0,arr=new Array(); for(var i=0;i<l;i+=1)arr.push(obj[i]); return arr; }; var ArraySlice=Array.prototype.slice; Array.prototype.slice=function(){ if(this===window||this===null||this===undefined){ throw new Error("Array.prototype.slice called on null or undefined"); } return ArraySlice.apply(parseArray(this),arguments); } } })();
若有高招,欢迎批评!