JavaScript中只有replace方法,并不提供replaceAll方法,再此只能自己写replaceAll方法了。
String.prototype.replaceAll = function(s1,s2){
return this.replace(new RegExp(s1,”gm”),s2);
}
或者使用
str.replace(new RegExp(s1,”gm”),s2);
本站技术交流群:24735919,欢迎大家进群交流探讨!
JavaScript中只有replace方法,并不提供replaceAll方法,再此只能自己写replaceAll方法了。
String.prototype.replaceAll = function(s1,s2){
return this.replace(new RegExp(s1,”gm”),s2);
}
或者使用
str.replace(new RegExp(s1,”gm”),s2);
近期评论