<html>
<head>
<script type="text/JavaScript">
function onlyNum(evt){
if(evt==null){
evt=window.event;
}
var keycode = evt.keyCode; //取得键盘码
//禁止输入shift+1,shift+2....shift+0输入符号。
if(evt.shiftKey && (keycode == 48 || keycode == 49 || keycode == 50 ||
keycode == 51 || keycode == 52 || keycode == 53 ||
keycode == 54 || keycode == 55 || keycode == 56 ||
keycode == 57) ){
evt.returnValue = false;
}
var realkey = String.fromCharCode(keycode);
//以键盘码转成键盘符号
if(keycode==8 ||keycode==9 || keycode==46||
(keycode>=35 && keycode<=40)||
(keycode>=96 && keycode<=105)){
return false;
}else if(!//d/.test(realkey)){
if(navigator.appName=="Netscape"){//区分浏览器种类
evt.preventDefault();
return false;
}else{
window.event.returnValue = false;
}
}
}
</script>
</head>
<body>
<table border=1>
<tr>
<td>
<input type="text" name="texts" οnkeydοwn="onlyNum(event);"/> 只能输入数字
</td>
</tr>
</table>
</body>
</html>
javascript 禁止输入shift 组合键
最新推荐文章于 2022-04-02 14:50:28 发布