只能输入正整数" type="hidden"/>

简单实现输入框 只能输入正整数


<style type="text/css">
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
}
</style>

...

<input type="number" placeholder="请输入正整数" onKeypress="inputCheck(event)" />

...

function inputCheck(e) {

  // 通过判断输入的charCode来过滤掉小数点和减号

  if (e.charCode == 45 || e.charCode == 46 || e.charCode == 69 || e.charCode == 101) {
    e.returnValue = false;
  }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM