Evento onkeyup
Ejemplo
Ejecuta un JavaScript cuando un usuario suelta una clave:
<input type="text" onkeyup="myFunction()">
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
El evento onkeyup ocurre cuando el usuario suelta una tecla (en el teclado).
Sugerencia: el orden de los eventos relacionados con el evento onkeyup:
- onkeydown
- onkeypress
- encendido
Compatibilidad con navegador
Event | |||||
---|---|---|---|---|---|
onkeyup | Yes | Yes | Yes | Yes | Yes |
Sintaxis
En HTML:
<element onkeyup="myScript">
En JavaScript:
object.onkeyup = function(){myScript};
En JavaScript, usando el método addEventListener():
object.addEventListener("keyup", myScript);
Nota: el método addEventListener() no es compatible con Internet Explorer 8 y versiones anteriores.
Detalles técnicos
Burbujas: | sí |
---|---|
Cancelable: | sí |
Tipo de evento: | TecladoEvento |
Etiquetas HTML compatibles: | Todos los elementos HTML, EXCEPTO: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> y <title> |
Versión DOM: | Eventos de nivel 2 |
Más ejemplos
Ejemplo
Usando "onkeydown" junto con el evento "onkeyup":
<input type="text" onkeydown="keydownFunction()" onkeyup="keyupFunction()">
Ejemplo
Muestra la clave real que se lanzó dentro de un campo de texto:
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>