jquery只能输入数字

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>只能输入数字</title>

    <script type="text/javascript" src="jquery-1.9.1.min.js"></script>


    <script type="text/javascript">

        $(function(){
            $('input[type=text]').keypress(function(e) {
              if (!String.fromCharCode(e.keyCode).match(/[0-9.]/)) {
                return false;
              }
            });
        });


    </script>



</head>
<body>


    <input type="text" style=" 190px;">


</body>
</html>
View Code
原文地址:https://www.cnblogs.com/Tanghongchang/p/7021147.html