Created
November 13, 2013 01:40
-
-
Save gepser/7442128 to your computer and use it in GitHub Desktop.
Mostrar u ocultar un div con la tecla ESC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Esta funcion va en el body onload | |
function CapturadorDeEventos(){ | |
if (window.addEventListener) { | |
window.addEventListener("keydown", compruebaTecla, false); | |
} else if (document.attachEvent) { | |
document.attachEvent("onkeydown", compruebaTecla); | |
} | |
} | |
function compruebaTecla(evt){ | |
var divX = document.getElementById("divParaOcultarMostrar") | |
var tecla = evt.which || evt.keyCode; | |
if(tecla == 27){ | |
if (divX.style.display == 'none' ){ | |
divX.style.display = 'block' | |
}else{ | |
divX.style.display = 'none' | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment