leohxj
3/24/2016 - 6:12 AM

leftpad: 左侧位数不足补字符

leftpad: 左侧位数不足补字符

function leftpad (str, len, ch) {
  str = String(str);

  var i = -1;

  if (!ch && ch !== 0) ch = ' ';

  len = len - str.length;

  while (++i < len) {
    str = ch + str;
  }

  return str;
}