1、
JS监听body区域
document.onkeydown = function(e){
var ev = document.all ? window.event : e;
if(ev.keyCode==13) {
//操作的业务逻辑
}
};
2、jq方式实现
1)监听某个输入框
$("#queryTable").bind("keydown",function(e){
// 兼容FF和IE和Opera
var theEvent = e || window.event;
var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
if (code == 13) {//操作的业务逻辑} });
2) 监听某个div的区域
$("#queryTable").bind("keydown",function(e){
// 兼容FF和IE和Opera
var theEvent = e || window.event;
var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
if (code == 13) {
//操作的业务逻辑} });
3、οnkeydοwn="enter(event)"方式实现
//回车事件执行方法
function enter(event) {
var browser = navigator.appName;
var userAgent = navigator.userAgent;
var code;
if(browser.indexOf('Internet')>-1) //IE
code = window.event.keyCode;
else if(userAgent.indexOf("Firefox")>-1) //火狐
code = event.which;
else //其它浏览器
code = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if ( code == 13){
//操作的业务逻辑
}
}