用到parseInt() 函数

parseInt() 函数可解析一个字符串,并返回一个整数

input框限制0开头的数字(0除外)

提示和注释

注释:只有字符串中的第一个数字会被返回。

注释:开头和结尾的空格是允许的。

提示:如果字符串的第一个字符不能被转换为数字,那么 parseFloat() 会返回 NaN。

w3c:http://www.w3school.com.cn/jsref/jsref_parseInt.asp

 

利用此特性使用parseInt(value,10)即可去除01,001等数字

<input type="text" value="" onKeyUp="value=(parseInt(value=value.replace(/\D/g,''),10))" /> 

还可以使用正则表达式直接判断

非负整数: ^[1-9]\d*|0$

  正整数:  ^[1-9]\d*$

相关文章:

  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案