posts - 10, comments - 9, trackbacks - 0, articles - 17

javascript中的replace与replaceAll

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);   

只有注册用户登录后才能发表评论。


网站导航: