jquery只能输入数字

时间:2023-12-22 16:54:26
<!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(/[-\.]/)) {
return false;
}
});
}); </script> </head>
<body> <input type="text" style="width: 190px;"> </body>
</html>