JavaScript为数字在左边自动补0的函数 leftZeroPad,例如:leftZeroPad(3, 2) 将返回 03
var MANY_ZEROS = "000000000000000000"; function leftZeroPad(val, minLength) { if (typeof(val) != "string") val = String(val); return (MANY_ZEROS.substring(0, minLength - val.length)) + val; }
例如:leftZeroPad(3, 2) ==> ”03″