当前位置:编程学习 > JS >>

js手写实现 jquery的replaceall方法,怎么实现?

追问:如何给dom附上这方法
答案:String.replaceall=function (oldstr,newstr){
var oldlength =this.length;
var ret =this.replace(oldstr,newstr);
if(ret.length<oldlength)
return ret.replaceall(oldstr,newstr);
returnt ret;
}

使用方法:
var teststr ="asdfasdfasdfasdfasdfasdfasdfasdfasdf";
alert(teststr.replaceall("as","df"));

上一个:本人现在37J的JS冲40在哪最好?
下一个:VB6.0 通过 Webbrowser 获取网页里的一些js变量的值?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,