Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用零(0)填充html输入_Javascript_Jquery_Html - Fatal编程技术网

Javascript 用零(0)填充html输入

Javascript 用零(0)填充html输入,javascript,jquery,html,Javascript,Jquery,Html,伙计们,我需要用零来填写一个输入,总是有6个字符。 例如: 用户输入数字23,键入时,其他4个字符为0: 我做了一些搜索,但没有找到,我不知道怎么做/ 试着这样做: function padSix(x) { if (x <= 999999) { x = ("00000"+ x).slice(-6); } return x; } 一种可能的解决方案: var el=document.getElementById'el'; var updatetext=

伙计们,我需要用零来填写一个输入,总是有6个字符。 例如: 用户输入数字23,键入时,其他4个字符为0:

我做了一些搜索,但没有找到,我不知道怎么做/

试着这样做:

function padSix(x) 
{
  if (x <= 999999) 
  { 
     x = ("00000"+ x).slice(-6); 
  }
  return x;
}

一种可能的解决方案:

var el=document.getElementById'el'; var updatetext=函数{ el.value='000000'+el.value.slice-6; } el.addEventListenerkeyup,updatetext,false;
嘿,给你一个好的。比答案好多了。
function padSix(x) 
{
  if (x <= 999999) 
  { 
     x = ("00000"+ x).slice(-6); 
  }
  return x;
}