开发者

Event JavaScript when Esc on click?

开发者 https://www.devze.com 2023-04-06 17:05 出处:网络
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){

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消