String.prototype.format = function(args) { var result = this; if (arguments.length > 0) { if (arguments.length == 1 && typeof (args) == "object") { for (var key in args) { if (args[key] != undefined) { var reg = new RegExp("({&qu…
String.prototype.format = function(args) { if (arguments.length > 0) { var result = this; if (arguments.length == 1 && typeof (args) == "object") { for (var key in args) { var reg = new RegExp("({" + key + "})", &q…
第一种方法: String.format = 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; }…
<script type='text/javascript'> String.format = function() { var s = arguments[0]; for (var i = 0; i < arguments.length - 1; i++) { var reg = new RegExp("\\{" + i + "\\}", "gm"); s = s.replace(reg, arguments[i + 1]);…