<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">

    </style>
    <script src="../jquery/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
        function test(event){
            var test = document.getElementById("test");
            if(event.keyCode<48 || event.keyCode>57){  //判断keyCode码
                return false;
            }
        }
    </script>
</head>
<body>

<input type="text" onkeypress="return test(event)" id="test">
</body>
</html>

 

版权声明:本文为alex-xxc原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/alex-xxc/p/9997022.html