There are three differences on msdn: Name Description
onkeypress
This event occurs when the user presses and releases any alphanumeric key. System buttons (for example, arrow keys and function keys) are not recognized.
onkeyup
This event occurs when the user releases any previously pressed keyboard key.
onkeydown
This event occurs when the user presses any keyboard key (including system buttons such as arrow keys and function keys).
======================
<script> <br>function checkForm(){ <br>if(event.keyCode ==13){ <br>event.keyCode =9; <br>} <br>} <br></script>
When Enter is pressed, the focus moves from the text box to the button. If you change it to "onkeypress", the focus will not shift or be lost. But if you change it to "onkeyup", the focus will be lost and the page will be reloaded.
The test found that the onkeydown event is executed first, followed by onkeypress, and finally onkeyup; onkeydown and onkeypress will affect the execution of onkeyup. If there are three event colleagues, if they are all alerts, only 2 alerts will pop up, and the alert for the up event will not pop up.
There is one difference in the event responses between the three, that is, the characters entered when responding to onkeydown and onkeypress events are not accepted by the system, but when responding to onkeyup, the input stream has been accepted by the system. Since onkeydown is executed before onkeypress, and based on the above example, we can know that the input stream is about to enter the system when onkeydown is triggered. That is to say, as soon as the onkeydown event is completed, the input stream enters the system and cannot be changed. Therefore, the onkeydown event can be used to change which key the user pressed; the onkeypress event is triggered after the input stream enters the system, but the input stream has not been processed by the system, and the input stream cannot be changed at this time; onkeyup is the input stream. Occurs after being processed by the system.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn