JQuery判断页面是否按下了Enter键

$('#someTextBox').keypress(function(event){  

    var keycode = (event.keyCode ? event.keyCode : event.which);  

if(keycode == '13'){  

        alert('You pressed a "enter" key in textbox');    

    }  

});  

$(document).keypress(function(event){  

    var keycode = (event.keyCode ? event.keyCode : event.which);  

if(keycode == '13'){  

        alert('You pressed a "enter" key in somewhere');      

    }  

});

 

posted @ 2016-03-25 12:43  lishidefengchen  阅读(323)  评论(0编辑  收藏  举报