Possible Duplicate:
js: how to find out what character key is pressed?




我想知道如何在按键时进行事件,并指定仅使用javascript按下哪个键。提前致谢

最佳答案

<script type="text/javascript">
    function myKeyPress(e){

        var keynum;

        if(window.event){ // IE
            keynum = e.keyCode;
        }else
            if(e.which){ // Netscape/Firefox/Opera
                keynum = e.which;
             }
        alert(String.fromCharCode(keynum));
    }
   </script>


 <form>
  <input type="text" onkeypress="return myKeyPress(event)" />
 </form>


How to find out what character key is pressed?引用

08-08 06:34