Fonctions onkeydown / onkeyup

posted in: html | 0

Appuyez et maintenez enfoncée une touche à l’intérieur du champ de texte pour définir une couleur de fond rouge. Relâchez la touche pour définir une couleur de fond vert.

 

Code expliqué

<p>Appuyez et maintenez enfoncée une touche à l’intérieur du champ de texte pour définir une couleur de fond rouge. Relâchez la touche pour définir une couleur de fond vert.

<input type= »text » id= »demo » onkeydown= »keydownFunction() » onkeyup= »keyupFunction() »>

<script>
function keydownFunction() {
document.getElementById(« demo »).style.backgroundColor = « red »;
}

function keyupFunction() {
document.getElementById(« demo »).style.backgroundColor = « green »;
}
</script>

logowebmaster1