Test results of keyCode, which, and charCode compatibility in Keyboard Events:
In IE:
> Supports keyCode.
> Which and charCode are not supported. Their values are undefined.
In Firefox:
> Supports keyCode. Except for function keys, other key values are always 0.
> Which and charCode are supported. The values are the same.
In Opera:
> Supports keyCode and which with the same values.
> CharCode is not supported and its value is undefined.
<Script type = "text/javascript"> // By fengyan @ IECN. Net function $ (s) {return document. getElementById (s )? Document. getElementById (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> press any Key to view the test result: </p> type: current Key: Decimal: keyCode: <strong> note: In FF, keyCode is always 0 </strong> which: <strong> note: in IE, which is always undefined; in Opera, the values of keyCode and charCode are the same </strong> charCode: <strong> note: in IE and Opera, charCode is always undefined; In FF, which and charCode have the same value. </strong> uppercase: altKey: ctrlKey: shiftKey: repeat: <style type = "text/css" media = "all"> body {color: #999; font: normal 14px tahoma, Homa, 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 select all Note: If you need to introduce external Js, You need to refresh it to execute]