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="width: 190px;">


</body>
</html>
View Code

 

posted @ 2017-06-15 23:45  唐宏昌  阅读(305)  评论(0编辑  收藏  举报