JS implementation of the keyboard enter key to submit the form of the method _javascript skills

Source: Internet
Author: User

This article illustrates the method of JS to implement the form of the keyboard enter key. Share to everyone for your reference. The implementation methods are as follows:

Perform keyboard key command
function KeyDown (e) { 
 var keycode = 0;
 IE browser
 if (Checkbrowserisie ()) {
  keycode = Event.keycode;
 } else{
 //firefox browser
 keycode = E.which;
 }
 if (keycode = 13)//Enter is
 {
  //document.getelementbyid ("Login"). Click ();
  document.getElementById ("LoginForm"). Submit ();
Determine if the visitor's browser is IE
function Checkbrowserisie () {
 var result = false;
 var browser = navigator.appname;
 if (browser = = "Microsoft Internet Explorer") {result
  = true;
 }
 return result;
}

Finally only need to add in the body: <body onkeydown= "KeyDown (event);" >.

Or the following methods, but in Firefox browser is not compatible:

function Document.onkeydown () {  
 if (event.keycode==13)  
 document.getElementById (' Loginfrom '). Submit ();


I hope this article will help you with your JavaScript programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.