jquery中判断是否按下回车键
在jquery中,可以通过如下的方法,检测是否按下了回车键
$('#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'); } });
注意,firefox是支持event.which去获得键的ascii码,而ie是同时支持
event.keyCode和event.which的
相关推荐
JINKAI 2011-10-26
卡奇莫多 2013-08-29
haleyyan 2011-12-27
maple00 2011-04-15
onethousand 2018-11-26
cjwsohu 2018-03-09
83453861 2017-11-21
zgwyfz 2019-04-26
demon00d 2019-04-26
stonerkuang 2019-04-25
87941037 2015-12-24
ericwuhk 2009-09-09
83457500 2019-04-18
83457500 2014-05-11
yaasshole 2014-05-11