//方法一
function FillZero(p) {
return new Array(3 - (p + '').length + 1).join('0') + p;
}
FillZero(6); //输出006
//方法一扩展(C#中PadLeft、PadRight)
String.prototype.PadLeft = function (len, charStr) {
var s = this + '';
return new Array(len - s.length + 1).join(charStr, '') + s;
}
String.prototype.PadRight = function (len, charStr) {
var s = this + '';
return s + new Array(len - s.length + 1).join(charStr, '');
}
var p = 6;
p.toString().PadLeft(3, '0'); //输出006
p.toString().PadRight(3, '0'); //输出600