About compatibility testing for keycode, which, and charcode in keyboard events _ basics

Source: Internet
Author: User
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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.