Home > Web Front-end > JS Tutorial > js method to implement keyboard Enter key to submit form_javascript skills

js method to implement keyboard Enter key to submit form_javascript skills

WBOY
Release: 2016-05-16 15:57:30
Original
2022 people have browsed it

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;
}
Copy after login

Finally, you only need to add to the body: .

Or the following method, but it is not compatible with Firefox:

function document.onkeydown(){  
 if(event.keyCode==13)  
 document.getElementById('loginFrom').submit();
}

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template