Javascript registers the carriage return event (sets the default button) method for the button, javascript event

Source: Internet
Author: User

Javascript registers the carriage return event (sets the default button) method for the button, javascript event

This example describes how to register a carriage return event (set the default button) with javascript. Share it with you for your reference. The details are as follows:

First of all, I have to say that I am really a rookie in JS. JS and some JS frameworks, such as JQuery, are only in the simple application stage, and of course they are constantly learning, I hope to share with you more about JS in the future. Today, let's start with appetizing and talk about how to set a default button, that is, whether the focus is not on the button, as long as you press enter, it is equivalent to triggering the button click event.

The code is very simple. To complete this function, you only need a few lines of code:

// Register the key event document for the keyListener method. onkeydown = keyListener; function keyListener (e) {// when you press the Enter key, run our code if (e. keyCode = 13) {// what we want to do }}

Well, it seems a little too simple. I am a little embarrassed to complete a blog in this way. Finally, we will attach an example of a small program:

<! DOCTYPE html> 

This small instance is very simple, and the code is very understandable, but the things behind the Code are not what the average person can understand. Raise your hand .....

I hope this article will help you design javascript programs.

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.