In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "what are the keyboard events of javascript". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope that this article "what are the keyboard events of javascript" can help you solve the problem.
Javascript has three kinds of keyboard events: 1, keydown event, triggered when a key is pressed on the keyboard; 2, keypress event, triggered when a keyboard key is pressed and released; and 3, keyup event, triggered when a keyboard key is released.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
In JavaScript, keyboard events are triggered when a user manipulates the keyboard.
There are three main types of keyboard events:
Keydown: triggered when a key is pressed on the keyboard. If you press and hold a key, the event will be triggered continuously, but Opera browsers do not support this continuous operation. When this event handler returns false, it cancels the default action (such as keyboard characters entered, and disables keypress event response in IE and Safari browsers).
Keypress: triggered when a keyboard key is pressed and released. If you press and hold a key, the event will be triggered continuously. When the event handler returns false, it cancels the default action (such as the keyboard character entered).
Keyup: triggered when a keyboard key is released. This event is triggered only once when the keyboard is released and is not a continuous response state.
When getting the key code that the user is pressing, you can use the keydown, keypress, and keyup events to get this information. The keydown and keypress events are basically synonymous and behave exactly the same, but some browsers do not allow the use of keypress events to get keystroke information. All elements support keyboard events, but keyboard events are often applied to form input.
Example
The following example captures various details of the keyboard operation in real time, that is, the keyboard response event type and the corresponding key value.
Var key = document.getElementById ("key"); key.onkeydown = f; / register keydown event handler key.onkeyup = f; / register keyup event handler key.onkeypress = f; / / register keypress event handler function f (e) {var e = e | | window.event; / / standardized event handling var s = e.type + "" + e.keyCode / / get the keyboard event type and the pressed value key.value = s;}
Keyboard event Properties
The keyboard defines a number of properties, as shown in the following table. Keyboard operation can be precisely controlled by using these properties. Keyboard event properties generally exist in the event object only when keyboard-related events occur, with the exception of the ctrlKey and shiftKey properties, as they can exist in soil and water conservation events. For example, click when you press the Ctrl or Shift key.
The attribute attribute defined by the keyboard event indicates that the attribute keyCode contains the key value of the corresponding key position in the keyboard charCode this attribute contains the Unicode code of the corresponding key position in the keyboard, only DOM supports the nodes where target events occur (including elements), only DOM supports the elements of srcElement events, and only IE supports whether shiftKey presses the Shift key, if it returns true, otherwise it means whether falsectrlKey presses the Ctrl key, if it returns true, otherwise it means whether falsealtKey presses the Alt key. If you press to return to true, otherwise it is whether falsemetaKey presses the Mtea key, if you press to return to true, otherwise it is false, only DOM supports the introduction of "what are the keyboard events of javascript" here, thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.