Test Results:
Under IE:
>> Support KeyCode
>> does not support which and charcode, the values are undefined
Under Firefox:
>> supports keycode, except function keys, the other key values are always 0
>> supports which and charcode, the values are the same
Under Opera:
>> supports KeyCode and which, the values are the same
>> does not support charcode, value is undefined
<script type= "Text/javascript" >//by maple @iecn.net function $ (s) {return document.getElementById (s)? Document.get Elementbyid (s): s; function Viewkeyinfo (e) {var currkey=0,capslock=0; var e=e| | Event currkey=e.keycode| | e.which| | E.charcode; Capslock=currkey >=65 && Currkey <=90; $ ("type"). innerhtml=e[' type ']; $ ("Currkey"). Innerhtml=string.fromcharcode (Currkey); $ ("Decimal"). Innerhtml=currkey; $ ("KeyCode"). innerhtml=e[' KeyCode ']; $ ("CharCode"). innerhtml=e[' CharCode ']; $ ("caps"). Innerhtml=capslock; $ ("Shiftkey"). innerhtml=e[' Shiftkey ']; $ ("Ctrlkey"). innerhtml=e[' Ctrlkey ']; $ ("repeat"). innerhtml=e[' Repeat ']; $ ("which"). innerhtml=e[' which ']; } document.onkeypress= Viewkeyinfo; </script> <p> Please press any key to see the test effect:</p> type:<span id= "type" ></span> current Key:<span id= "Currkey "></span> decimal:<span id=" Decimal "></span> keycode:<span id=" KeyCode "></span> <strong> Note: Under FF, KeyCode is always 0</strong> which:<span id= "which" ></span> <strong> Note: under IE, which is always undefined; under opera, KeyCode and CharCode are the same values </strong> charcode:<span id= "CharCode" ></span> <strong> Note: Under IE, opera, charcode always for undefined; Under FF, the values for which and charcode are the same </strong> uppercase: <span id= "caps" ></span> altkey:<span id= "Altkey" > </span> ctrlkey:<span id= "Ctrlkey" ></span> shiftkey:<span id= "Shiftkey" ></span> Repea T:<span id= "Repeat" ></span> <style type= "Text/css" media= "all" > body {color: #999; font:normal 14px ta Homa, XXFarEastFont-Arial, Geneva,arial,sans-serif; span {color: #f00; font-weight:bold;padding:0 5px;} Strong {color: #090; font-weight:normal;padding:0 5px;} </style>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]