String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
"{0} is dead, but {1} is alive! {0} {2}".format("ASP", "ASP.NET")
输出:
ASP is dead, but ASP.NET is alive! ASP {2}让javascript中想C#中的string.Format()一样的功能。还有其余的好的方法吗。
添加回答
举报
0/150
提交
取消