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.