javascript的replaceAll();

http://thoreau.javaeye.com/blog/648634

js中没有java中的replaceAll()函数,为了达到与java的replaceAll()一样的效果,我们可以用如下代码实现:

String.prototype.replaceAll = function(s1,s2) {

    return this.replace(new RegExp(s1,"gm"),s2);

}

调用方式:

如想替换字符串"aa bb cc"中的所有空格,可以执行"aa bb cc".replaceAll(" ", "");

posted on 2010-06-23 16:33  冰危节奏  阅读(183)  评论(0)    收藏  举报

导航