实现js的replaceAll方法

真是愁人!js居然不提供replaceAll方法,用for循环又有效率问题,给你一个正则表达式的解决方案

js 代码
  1. String.prototype.replaceAll  =  function (s1,s2){   
  2. return   this .replace( new  RegExp(s1, "gm" ),s2);   
  3. }  

猜你喜欢

转载自blog.csdn.net/fengchunlei2008/article/details/5914277