<!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>