- 方法一:
document.onkeydown = function (e) { // 回車提交表單 // 兼容FF和IE和Opera var theEvent = window.event || e; var code = theEvent.keyCode || theEvent.which || theEvent.charCode; if (code == 13) { queryInfo(); } }
- 方法二:
JS監聽某個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) { //回車執行查詢 $("#queryButton").click(); } });
JS監聽某個輸入框
//回車事件綁定 $('#search_input').bind('keyup', function(event) { if (event.keyCode == "13") { //回車執行查詢 $('#search_button').click(); } });