实现js的replaceAll方法
2015-02-11 01:02
369 查看
js不提供replaceAll方法,要用正规表达式实现
第一种:
String.prototype.replaceAll = function(s1,s2){
return this.replace(new RegExp(s1,"gm"),s2);
}
第二种:
str =str.replace(/&/g,"@");//将str串中的&替换成@
转载自:http://www.csdn.net/article/a/2009-12-08/258255
第一种:
String.prototype.replaceAll = function(s1,s2){
return this.replace(new RegExp(s1,"gm"),s2);
}
第二种:
str =str.replace(/&/g,"@");//将str串中的&替换成@
转载自:http://www.csdn.net/article/a/2009-12-08/258255
相关文章推荐
- js 实现ReplaceAll 的方法
- js 实现ReplaceAll 的方法
- 实现JS中的 replaceAll 方法
- js 实现ReplaceAll 的方法
- 实现js的replaceAll方法
- js实现C#的replaceAll()的方法
- js 实现ReplaceAll 的方法
- js 实现ReplaceAll 的方法
- 实现js的replaceAll方法
- Js 实现 replaceAll 方法
- js 字符串的replace() 方法和实现replaceAll() 方法
- js 实现ReplaceAll 的方法
- 实现js的replaceAll方法
- js 实现ReplaceAll 的方法(3种方式)
- 六十、js 实现replaceAll 方法
- js/jq替换方法replaceAll的实现
- 在js中,实现replaceAll的方法
- js 实现ReplaceAll 的方法 .
- js中实现replaceAll方法
- js实现replaceAll方法与正则中引用变量