手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >fix-ie5.js扩展在IE5下不能使用的几个方法
fix-ie5.js扩展在IE5下不能使用的几个方法
摘要:在IE5下的Javascript:Array不支持push(),pop();Function不支持apply();String对象的repl...

在IE5下的Javascript:

Array不支持push(),pop();Function不支持apply();String对象的replace方法不支持替换成一个处理函数。

使用下面的代码就可修复上述方法在IE5下无效的问题。

/*

fix-ie5.js,version1.0(pre-release)(2005/05/15)x3

Copyright2005,DeanEdwards

Web:http://dean.edwards.name/

ThissoftwareislicensedundertheCC-GNULGPL

Web:http://creativecommons.org/licenses/LGPL/2.1/

*/

if(/MSIE5.0/.test(navigator.userAgent))newfunction(){

var$$apply=function($function,$object,$arguments){

$function.apply($object,$arguments);

};

//fixString.replace

if(''.replace(/^/,String)){

//preserveString.replace

var_stringReplace=String.prototype.replace;

//createString.replaceforhandlingfunctions

var_functionReplace=function($expression,$replacement){

var$match,$newString="",$string=this;

while($string&&($match=$expression.exec($string))){

$newString+=$string.slice(0,$match.index)+$$apply($replacement,this,$match);

$string=$string.slice($match.lastIndex);

}

return$newString+$string;

};

//replaceString.replace

String.prototype.replace=function($expression,$replacement){

this.replace=(typeof$replacement=="function")?_functionReplace:_stringReplace;

returnthis.replace($expression,$replacement);

};

}

//fixFunction.apply

if(!Function.apply){

varAPPLY="apply-"+Number(newDate);

$$apply=function(f,o,a){

varr;

o[APPLY]=f;

switch(a.length){//deconstructforspeed

case0:r=o[APPLY]();break;

case1:r=o[APPLY](a[0]);break;

case2:r=o[APPLY](a[0],a[1]);break;

case3:r=o[APPLY](a[0],a[1],a[2]);break;

case4:r=o[APPLY](a[0],a[1],a[2],a[3]);break;

default:

varaa=[],i=a.length-1;

doaa[i]="a["+i+"]";while(i--);

eval("r=o[APPLY]("+aa+")");

}

deleteo[APPLY];

returnr;

};

//fixICommon

ICommon.valueOf.prototype.inherit=function(){

return$$apply(arguments.callee.caller.ancestor,this,arguments);

};

}

//arrayfixes

if(![].push)Array.prototype.push=function(){

for(vari=0;i<arguments.length;i++){

this[this.length]=arguments[i];

}

returnthis.length;

};

if(![].pop)Array.prototype.pop=function(){

var$item=this[this.length-1];

this.length--;

return$item;

};

};

【fix-ie5.js扩展在IE5下不能使用的几个方法】相关文章:

javascript判断并获取注册表中可信任站点的方法

Node.js中JavaScript操作MySQL的常用方法整理

Jquery解析json字符串及json数组的方法

js去除浏览器默认底图的方法

在JavaScript中使用NaN值的方法

JavaScript中使用Math.PI圆周率属性的方法

Javascript实现每日自动换一张图片的方法

js判断鼠标位置是否在某个div中的方法

js控制div弹出层实现方法

js+html5实现canvas绘制圆形图案的方法

精品推荐
分类导航