这是搜索来得结果: <mce:script type="text/javascript"><!-- //V1 method String.prototype.formate = function () { var args = arguments; return this.replace(//{(/d+)/}/g, function (m, i) { return args[i]; }); } //V2 static String.formate = function () { if (arguments.length == 0) return null; var str = arguments[0]; for (var i = 1; i < arguments.length; i++) { var re = new RegExp('//{' + (i - 1) + '//}', 'gm'); str = str.replace(re, arguments[i]); } return str; } var a = "I Love {0}, and You Love {1},Where are {0}! {4}"; alert(String.formate(a, "You", "Me")); alert(a.formate("You", "Me")); // --></mce:script>