//Netscape/Firefox/Opera中不支持 window.event.keyCode,需要用event.which代替//IE用event.keCode方法获取当前被按下的键盘按键值,//而NetScape/FireFox/Opera用的则是event.which
例:
<html><body> <script type="text/javascript"> function noNumbers(e){ var keynumvar keycharvar numcheck if(window.event) // IE{keynum = e.keyCode } else if(e.which) // Netscape/Firefox/Opera {keynum = e.which} keychar = String.fromCharCode(keynum) numcheck = /d/return !numcheck.test(keychar)} </script> <form> <input type="text" onkeypress="return noNumbers(event)" /> </form></html>
时间: 2024-10-03 22:38:55