<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
window.onload = function(){
var text1 = document.getElementById('text1');
//键盘按下事件
text1.onkeydown = function(ev){
var oEvent = ev || event;
//判断按下的键是否过滤掉
if(oEvent.keyCode != 8 && (oEvent.keyCode<48 || oEvent.keyCode>57)){
//返回false,符合条件的按键会被屏蔽掉
return false;
}
};
};
</script>
</head>
<body>
<input type="text" id="text1"/>
</body>
</html>