JavaScript registers a carriage return event for a button (setting the default button)

Source: Internet
Author: User

This article mainly introduced JavaScript for the button Register carriage return event (set the default button) method, you can press the ENTER key trigger button press the effect, very simple and practical, need friends can refer to the

First of all have to say, in JS aspect, oneself really is a rookie. For JS and some JS framework such as jquery, such as the JS framework, they are only in the simple application stage, of course, they are also in constant learning, I hope that in the future with you to share more JS experience. Let's start with an appetizer today. How to set a default button, that is, no matter the focus is not on the button, just press ENTER, it is the trigger button click event.

The code is very simple, to complete this function, just a few lines of code:

?

1 2 3 4 5 6 7 8 Registers the key event Document.onkeydown=keylistener for the KeyListener method; function KeyListener (e) {//When the ENTER key is pressed, execute our code if (E.keycode = 13) {//What we are going to do}}

Well, it seems a little too simple, so complete a blog, I am a bit embarrassed. Finally, we enclose an example of a small program:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 The

This small example is very simple, the code is very understood, but the thing behind the code is not common people can understand. Please raise your hand to understand.

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

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.