//扩展方法
$.GM.Format = function (source, params) { if (arguments.length == 1) return function () { var args = $.makeArray(arguments); args.unshift(source); return $.format.apply(this, args); }; if (arguments.length > 2 && params.constructor != Array) { params = $.makeArray(arguments).slice(1); } if (params.constructor != Array) { params = [params]; } $.each(params, function (i, n) { source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n); }); return source; }
调用:
var strTableTemplate = "<td>{0}-{1}-{2}</td>"
var
strTemplate = $.GM.Format(strTableTemplate, str1,str2,str3);