JS press the Enter key to log on. js press the Enter key to log on.

Source: Internet
Author: User

JS press the Enter key to log on. js press the Enter key to log on.

This article describes how to log on by pressing the Enter key in JS. This function has a wide range of practical values. Share it with you for your reference. The specific method is as follows:

Method 1:

<Html xmlns = "http://www.w3.org/1999/xhtml"> 

Method 2:

<script>function KeyDown(){  if (event.keyCode == 13)  {    event.returnValue=false;    event.cancel = true;    Form1.btnsubmit.click();  }}</script>

Usage:

<Form name = "Form1" method = ""> Username: <input type = text SIZE = 20 maxlength = 8 onkeydown = KeyDown ()> password: <input type = password SIZE = 20 maxlength = 8 onkeydown = KeyDown ()> <input type = "submit" name = "btnsubmit" value = "submit"/> </form>

Method 3:

Any website page has a logon interface. Many times, after you have entered your username and password, you need to click a button or link similar to what you are logging on. in this way, you can enter the website to do what you like.
Sometimes I wonder if I can directly press enter to execute the login function after entering the input? The solution is as follows:

Ss.html Page code:

<Html> 

HereNote:In <body>, we added the onkeydown attribute so that after entering the content, we can press the key to directly execute the JS method on_return. because window. event. if the keyCode is 13, it indicates the Enter key. Therefore, we can judge whether the key we press is a return key. If so, we can find the 'sub 'attribute. If we find the key, we can execute the click method.

I hope the method described in this article will be helpful for your web programming.


How does js achieve the same effect as clicking the mouse? The code is concise and compatible with the following demo:

<Form method = "post" name = "" action = "" onkeydown = "javascript: if (event. keyCode = 13) this. submit ();">

<Input type = "text" name = "" value = "" maxlength = "" placeholder = "input data here"/> <br/>
<Input type = "submit" name = "" value = "after entering data, click here or press the Enter key to execute" id = ""/>
</Form>

How does ASP or JS implement a page button and press enter as the shortcut key?

Write down JS events, capture keys, judge, and execute the process you want.

Function document. onkeydown () // trigger by pressing enter in the webpage
{
If (event. keyCode = 13)
{
// Here is the process.
Form1.submit (); // submit
// Alert ("OK ");
Return false;

}
}

Related Article

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.