前端 JavaScript控制回车键进行表单(form)提交
提交表单
<script>
document.onkeydown = function (e) {
// 回车提交表单
var theEvent = window.event || e;
var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
if (code === 13) {
add_team_member();
return false;
}
return true;
}
</script>
其他方法:
监听某个区域
document.onkeydown = function (e) { // 回车提交表单
// 兼容FF和IE和Opera
var theEvent = window.event || e;
var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
if (code == 13) {
queryInfo();
}
}
监听某个输入框
//回车事件绑定
$('#search_input').bind('keyup', function(event) {
if (event.keyCode == "13") {
//回车执行查询
$('#search_button').click();
}
});
具体需求可更具代码进行相应的改动即可使用。