onkeyup-händelse
Definition and usage
The onkeyup event occurs when the user releases a key (on the keyboard).
Tip:Event order related to onkeyup event:
Example
Example 1
Execute JavaScript when the user releases a key:
<input type="text" onkeyup="myFunction()">
Example 2
Use "onkeydown" and "onkeyup" events together:
<input type="text" onkeydown="keydownFunction()" onkeyup="keyupFunction()">
Example 3
Output the actual key released in the text field:
Enter your name: <input type="text" id="fname" onkeyup="myFunction()"> <script> function myFunction() { var x = document.getElementById("fname").value; document.getElementById("demo").innerHTML = x; } </script>
Syntax
In HTML:
<element onkeyup="myScript">
In JavaScript:
object.onkeyup = function(){myScript};
In JavaScript, use the addEventListener() method:
object.addEventListener("keyup", myScript);
Note:Internet Explorer 8 or earlier versions do not support addEventListener() method.
Technical details
Bubbling: | Stöd |
---|---|
Cancelable: | Stöd |
Event types: | KeyboardEvent |
Supported HTML tags: | All HTML elements except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> and <title> |
DOM-version: | Nivå 2-händelser |
Webbläsarstöd
Händelser | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
onkeyup | Stöd | Stöd | Stöd | Stöd | Stöd |