The example in this article describes how to implement the keyboard Enter key to submit a form using js. Share it with everyone for your reference. The specific implementation method is as follows:
//执行键盘按键命令 function keyDown(e){ var keycode = 0; //IE浏览器 if(CheckBrowserIsIE()){ keycode = event.keyCode; }else{ //火狐浏览器 keycode = e.which; } if (keycode == 13 ) //回车键是13 { //document.getElementById("login").click(); document.getElementById("loginform").submit(); } } //判断访问者的浏览器是否是IE function CheckBrowserIsIE(){ var result = false; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ result = true; } return result; }
Finally, you only need to add to the body:
.function document.onkeydown(){ if(event.keyCode==13) document.getElementById('loginFrom').submit(); }
I hope this article will be helpful to everyone’s JavaScript programming design.