JavaScript Tutorial/Document/onkeypress

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

document.onkeypress

The onKeyPress event handler specifies what should happen when any key is pressed when the Document object is in focus.



<html>
    <head>
    <script language="JavaScript1.2">
    <!--
    document.onkeypress = myKeyPressHandler;
    function myKeyPressHandler() {
      alert("A key press event took place within the document!");
    }
    -->
    </script>
    </head>
    <body>
    press a key within this document.
    </body>
    </html>


Document onkeypress event action

<html>
<head>
<script language="JavaScript" type = "text/javascript">
<!--
document.onkeypress = DisplayMsg;
function DisplayMsg()
{
    window.alert("You just pressed a key.");
}
//-->
</script>
<title>Keyboard Event</title>
</head>
<body>
</body>
</html>