How to ma开发者_C百科ke the event when the Esc key is pressed; please give me an example of an alert ();
.
document.body.onkeyup = function(e){
if(e.keyCode == 27){
alert('Yay');
}
}
if your interested in using jquery
,
check this code
<script type="text/javascript">
$("CssSelector").on("keyup", HandleKeyEvent(e));
function HandleKeyEvent(e)
{
if ( e.keyCode == 27 && e.key == "Escape" )
{
//--> Do Something
alert("It Works");
}
} );
</script>
Sorry I have just realized that this is an old question from 2011.
精彩评论