JavaScript Reference/Javascript Properties/keyCode — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 08:22, 26 мая 2010

"keyCode" Example

    
<html>
<body>
<script language="JavaScript">
    function function1() {
        x = event.keyCode; alert("Unicode Value: "+x);
    }
    function function2() {
        x = event.keyCode; alert("Keyboard Value: "+x);
    }
</script>
<p>Press Any Key While The Browser is in Focus</p>
<body onKeyDown="function2();" onKeyPress="function1();">
</body>
</html>



"keyCode" is applied to

+----------------+--------------------------------------------------------------+
| Applied_To     |event                                                         |
+----------------+--------------------------------------------------------------+



"keyCode" Syntax and Note

Note:
Read-only property. 
Returns the key code pressed. 
Used with the onKeyDown, onKeyUp, and onKeyPress events.
onKeyPress event,        the return value is in Unicode. 
                         This code distinguishes between uppercase and 
                         lowercase characters. 
---------------------------------------------------------------------------
onKeyDown and            the return value code is a character code.
onKeyUp events,          
    
Syntax:
    
window.event.keyCode