当前位置: 代码迷 >> JavaScript >> js的replaceall步骤
  详细解决方案

js的replaceall步骤

热度:269   发布时间:2012-08-31 12:55:03.0
js的replaceall方法
js中只包括replace方法不提供replaceAll方法 用for循环又有效率问题,用一个正则表达式的解决方案(gm  g=global, m=multiLine)

String.prototype.replaceAll  = function(s1,s2){
return this.replace(new RegExp(s1,"gm"),s2);
}

之后就可以使用replaceAll方法了
  src.replaceAll("<br>","\r\n")