javascript限制只能输入数字

html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>title>
    <script>
        window.onload=function(){
            var jNum = document.getElementById("number");
            function clearNonumber(obj){
                obj.value = obj.value.replace(/\D/g,"");

            }
            jNum.onfocus = function(){
                clearNonumber(this);
            };

            jNum.onkeyup = function(){
                clearNonumber(this);
            };
            jNum.onblur = function(){
                clearNonumber(this);
            }
        };
        
    script>
head>
<body>
    <input type="text" id="number" placeholder="只能输入数字" value="">
body>
html>

你可能感兴趣的:(javascript)