1.原因:浏览器版本问题
2.解决方案
(1)str.replace(new RegExp(“r”,‘g’),“R”)//把r替换成R
(2)str.replace(/r/g,“R”)//把r替换成R
(3)String.prototype.replaceAll = function(s1,s2){ return this.replace(new RegExp(s1,“g”),s2); }
注:g 执行全局匹配
1.原因:浏览器版本问题
2.解决方案
(1)str.replace(new RegExp(“r”,‘g’),“R”)//把r替换成R
(2)str.replace(/r/g,“R”)//把r替换成R
(3)String.prototype.replaceAll = function(s1,s2){ return this.replace(new RegExp(s1,“g”),s2); }
注:g 执行全局匹配