Home > Article > Web Front-end > How to implement input type=number to prohibit input of decimals
Recently, a project requirement is that the input box can only input numbers, and the input of decimals is prohibited.
intpu type=number can control the input of only numbers, but cannot control the input of decimals.
Find relevant information online and sort it out The
code is as follows
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>input type=number 禁止输入小数点</title> <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> <script src="jquery.min.js" type="text/javascript"></script></head><body> <input type="text" name="number" id='number'/><script>$(document).ready(function(){ var ipt = $('#number'); ipt.on('keyup',function(){ if(! /^\d+$/.test(this.value)){ this.value=''; } }) });</script></body></html>
The above is the detailed content of How to implement input type=number to prohibit input of decimals. For more information, please follow other related articles on the PHP Chinese website!