(1)监听某个输入框
$('#search_input').bind('keyup', function(event) { if (event.keyCode == "13") { //回车执行查询 $('#search_button').click(); } });
(2)监听某个区域
$("#queryTable").bind("keydown",function(e){ // 兼容FF和IE和Opera var theEvent = e || window.event; var code = theEvent.keyCode || theEvent.which || theEvent.charCode; if (code == 13) { //回车执行查询 $("#queryButton").click(); } });
(3)监听body
//回车事件 document.onkeydown = function (event) { var e = event || window.event; if (e && e.keyCode == 13) { //回车键的键值为13 $("#login").click(); //调用登录按钮的登录事件 } };