String.prototype.format=function(format)
{
var args = Array.prototype.slice.call(arguments, 1);
return format.replace(/\{(\d+)\}/g,function(m,i){ return args[i];});
}
var cls = 'my-class', text = 'Some text';
var s =String.format('<div class="{0}">{1}</div>', cls, text);
alert(s);运行说没有这个方法??
{
var args = Array.prototype.slice.call(arguments, 1);
return format.replace(/\{(\d+)\}/g,function(m,i){ return args[i];});
}
var cls = 'my-class', text = 'Some text';
var s =String.format('<div class="{0}">{1}</div>', cls, text);
alert(s);运行说没有这个方法??
String.prototype.format=function()
{
var args = Array.prototype.slice.call(arguments, 0);
return this.replace(/\{(\d+)\}/g,function(m,i){ return args[i];});
}
var cls = 'my-class', text = 'Some text';
var s = '<div class="{0}">{1}</div>'.format(cls, text);
alert(s);
String.format=function(format)
{
var args = Array.prototype.slice.call(arguments, 1);
return format.replace(/\{(\d+)\}/g,function(m,i){ return args[i];});
}
var cls = 'my-class', text = 'Some text';
var s =String.format('<div class="{0}">{1}</div>', cls, text);
alert(s);