Home  >  Article  >  Web Front-end  >  How to implement input type=number to prohibit input of decimals

How to implement input type=number to prohibit input of decimals

一个新手
一个新手Original
2017-10-10 10:18:1410276browse

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=&#39;number&#39;/><script>$(document).ready(function(){
    var ipt = $(&#39;#number&#39;);
    ipt.on(&#39;keyup&#39;,function(){
        if(! /^\d+$/.test(this.value)){            
        this.value=&#39;&#39;;
        }
    })
});</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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn