Home>

Please use the keyboard to enter some characters,These characters are displayed in the blank space of the web page.Is it missing something like a text box or text field,Feeling uncomfortable?This effect is to apply the document.onkeypress object in javascript to monitor every movement of the keyboard,And record which keys were pressed,Is it interestingFriends who want to study js, start with these small examples.

The screenshot of the running effect is as follows:

The online demo address is as follows:

The specific code is as follows:

<html>
<head>
<title>Display the pressed key on the page</title>
<script language="javascript">
<!-
 str="";
 function showkey () {
  asc=event.keycode;
  key=string.fromcharcode (asc);
  str +=key;
  txt.innerhtml=str;
 }
 document.onkeypress=showkey;
->
</script>
</head>
<body>
Please enter text using the keyboard:
<div></div>
</body>
</html>
  • Previous jQuery Ajax display loading animation asynchronously while loading data
  • Next Log4j different modules output to different files