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