Home > Web Front-end > HTML Tutorial > onkeyup,onkeydown和onkeypress_html/css_WEB-ITnose

onkeyup,onkeydown和onkeypress_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:54:23
Original
1347 people have browsed it

The following code:


<script><br> function checkForm(){<br> if(event.keyCode ==13) {<br> event.keyCode =9;<br> }<br> }<br> </script>


< ;input type="text" name = "text1" onkeydown = "checkForm()">



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 to "onkeyup", the focus will be lost and the page will be reloaded. 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).


(But in the test, onkeypress seems to recognize both arrows and function keys, strange!). The reason why onkeyup refreshes the page is unknown. I wonder if the browser has a default execution event for onkeyup, and its default execution event is to reload the page. To be found out later! Another thing to note is that the same value on the keyboard may correspond to onkeypress and onkeydown (onkeyup is generally the same as onkeydown). For example, "1" on the small keyboard, the corresponding onkeypress value is 49, while onkeydown and onkeyup Then they are all 97! There is an example on msdn, which can be used to check the different event values ​​corresponding to different keyboard values. url: http://msdn.microsoft.com/library/en-us/dnacc/html/Example3_Calculator.asp

Category: Web front-end

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template