Jangogo : 
//V1 method
String.prototype.format = function()
{
 var args = arguments;
 return this.replace(/\{(\d+)\}/g, 
function(m,i){
 return args;
 });
}
 
//V2 static
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);
 }
 return str;
} 
var a = "I Love {0}, and You Love {1},Where are {0}! {4}";
alert(String.format(a, "You","Me")); 
alert(a.format("You","Me"));

文档中心
Copyright © 2000-2016 粤ICP05021785号
地址:广州市天河区员村二横路8号全丰商业大厦808室 邮编:510600