Home > Web Front-end > JS Tutorial > body text

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

一个新手
Release: 2017-10-10 10:18:14
Original
10297 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template