<script> | |
function sendsubmit() | |
{ | |
$("#userLoginForm").submit(); | |
return false; | |
} | |
$(document).keypress(function(event){ | |
var keycode = (event.keyCode ? event.keyCode : event.which); | |
if(keycode == '13'){ | |
$("#userLoginForm").submit(); | |
return false; | |
} | |
}); | |
</script> |
在jquery中,可以通过如下的方法,检测是否按下了回车键
$('#someTextBox').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == ''){
alert('You pressed a "enter" key in textbox');
}
}); $(document).keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == ''){
alert('You pressed a "enter" key in somewhere');
}
});
注意,firefox是支持 event.which去获得键的ascii码,而ie是同时支持
event.keyCode和 event.which的