在vb中,要进行文本框输入字符的限制(比如说只可以输入数字),如果用change事件来控制的话会很慢,而且有的时候还能够看到光标的删除动作!要是用keydown来做就容易了!
<script language="javascript">
function KeyPress()
{
var l_key=window.event.keyCode;
switch(l_key)
{
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
case 58:
case 8:
{
break;
}
default:
{
window.event.keyCode=0;
break;
}
}
}
</script>
</head>
<body>
<input type="text" onKeyPress="KeyPress()" >
</body>
</html>
function KeyPress()
{
var l_key=window.event.keyCode;
switch(l_key)
{
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
case 58:
case 8:
{
break;
}
default:
{
window.event.keyCode=0;
break;
}
}
}
</script>
</head>
<body>
<input type="text" onKeyPress="KeyPress()" >
</body>
</html>