js监听键盘提交表单
Posted zhanxuewei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js监听键盘提交表单相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html> <html> <head> <title>登陆系统</title> <link href="/nmm/Public/User/css/user.css" rel="stylesheet"> <link href="/nmm/Public/css/bootstrap.min.css" rel="stylesheet"> <script type="text/javascript" src="/nmm/Public/js/jquery.min.js"></script> <script type="text/javascript" src="/nmm/Public/User/js/user.js"></script> <script type="text/javascript"> if (top.window !== window) { top.location = window.location; } //执行键盘按键命令 function keyDown(e) { var keycode = 0; //IE浏览器 if (CheckBrowserIsIE()) { keycode = event.keyCode; } else { //火狐浏览器 keycode = e.which; } if (keycode == 13) //回车键是13 { $("#btn-save").click(); } } //判断访问者的浏览器是否是IE function CheckBrowserIsIE() { var result = false; var browser = navigator.appName; if (browser == "Microsoft Internet Explorer") { result = true; } return result; } </script> </head> <body class="login" onkeydown="keyDown(event);"> <form name="forms"> <div class="login_m"> <div class="login_logo"> <h1>NMM 信息发布系统</h1> </div> <div class="login_boder"> Type :quit<Enter> to exit Vim 47,4-25 29% <button type="button" id="btn-save" class="btn btn-primary" onclick="return check();">登陆</button> </p> </div> </div> </div> <div class="text-center"> </div> </form> <!-- Modal --> <div class="modal fade" id="msgModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"> <span aria-hidden="true">×</span><span class="sr-only">Close</span> </button> <h4 class="modal-title" id="msgModalLabel"></h4> </div> <div class="modal-body text-center" id="msgModalBody"></div> <div class="modal-footer"> <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button> </div> </div> </div> </div> </body> </html>
以上是关于js监听键盘提交表单的主要内容,如果未能解决你的问题,请参考以下文章