<body> <input type="text" placeholder="只能输入数字"> <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script> <script> $("input").on("input",function(){ var result=$(this).val(); result=result.replace(/D/g,""); $(this).val(result) }); </script> </body>