js中有没有replaceall()方法? replaceall() 如何实现 ?

1.  js 中没有replaceall方法,jQuery中的replaceall()方法都是自己封装的。


2.

//参数1:原字符串,参数2:要替换的字符串,参数3:代替的字符串; 

 function replaceall( restr ,oldstr, newstr ){

            while (restr.indexOf(oldstr)  >= 0){

                    restr = restr.replace(oldstr,newstr);

                }

            return restr ;

    }


猜你喜欢

转载自blog.csdn.net/qq_20446879/article/details/79534721