Posted on 2010-07-07 09:44
wesley1987 阅读(1057)
评论(0) 编辑 收藏
在js中写了个替换字符的句子, 然后才知道原来js没有replaceAll方法, 就是说用replace的话, 他自会替换一次.
自定义replaceAll方法,
String.prototype.replaceAll = function(s1,s2){
return this.replace(new RegExp(s1,"gm"),s2);
}
gm g=global, m=multiLine ,
或直接 string = string..replace(new RegExp(s1,"gm"),s2);