String.prototype.replaceAll = function (targetStr, newStr) {
var sourceStr = this.valueOf();
while (sourceStr.indexOf(targetStr) !== -1) {
sourceStr = sourceStr.replace(targetStr, newStr);
}
return sourceStr;
};
转载于:https://www.cnblogs.com/andremao/p/9008807.html