There are three differences on msdn:
Description
Onkeypress
This event occurs when the user presses and releases any alphanumeric key. System buttons (for example, arrow keys and function keys) cannot be identified.
Onkeyup
This event occurs when the user releases any previously pressed keyboard keys.
Onkeydown
This event occurs when you press any keyboard key (including system buttons, such as the Arrow keys and function keys.
======================================
Copy codeThe Code is as follows:
<Html>
<Script>
Function checkForm (){
If (event. keyCode = 13 ){
Event. keyCode = 9;
}
}
</Script>
<Body>
<Form name = "form1">
<Input type = "text" name = "text1" onkeydown = "checkForm ()">
<Input type = "button" name = "button1" value = "button">
</Form>
</Body>
</Html>
When you press enter, the focus is moved from the text box to the button. If you change it to "onkeypress", the focus will not be transferred or lost. However, if you change to "onkeyup", the focus will be lost and the page will be reloaded.
Test shows that the onkeydown event is first executed, followed by onkeypress, and finally onkeyup; onkeydown and onkeypress will affect the onkeyup execution. If all three event colleagues are alert, only two alert events will be displayed, and the alert events of the up event will not be displayed.
There is another difference between the three in Event Response: The characters entered in the onkeydown and onkeypress event response are not accepted by the system, and the input stream is accepted by the system in response to onkeyup. Since onkeydown is executed before onkeypress, we can see from the above example that the input stream is about to enter the system when onkeydown is triggered. That is to say, once the onkeydown event is complete, the input stream enters the system and cannot be changed. Therefore, the onkeydown event can be used to change the key that the user presses, while the onkeypress event is triggered after the input stream enters the system. However, the input stream is not processed by the system and cannot be changed; onkeyup occurs after the input stream is processed by the system.