添加原型方法 String.prototype.replaceAll = function(s1, s2) { return this.replace(new RegExp(s1, "gm"), s2); } var str = "aaa"; var str2 = str.replaceAll("aaa", "bbb"); console.log(str2);