Home > Article > Web Front-end > What is the event of JavaScript learning? What are events used for?
This article will introduce to you what is the event of JavaScript learning? What are events used for? , let everyone know what commonly used events are and what events can do. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
First we understandWhat is an event?
Events are behaviors that can be detected by JavaScript.
HTML events are things that happen to HTML elements.
When JavaScript is used in an HTML page, JavaScript can trigger these events.
HTML events
HTML events can be browser behaviors or user behaviors.
Every element in an HTML web page can generate certain events that can trigger JavaScript functions.
The following are examples of HTML events:
##HTML page completes loading
When the HTML input field changes
HTML button is clicked
Usually when an event occurs, something can be done.
When an event is triggered, JavaScript can execute some code.
Event attributes can be added to HTML elements and JavaScript code can be used to add HTML elements.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <span id="demo"></span> <button onclick='getElementById("demo").innerHTML=Date()'>时间</button> </body> <script type="text/javascript"> </script> </html>
In the above example, the JavaScript code will modify the content of the element with id="demo".
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <span id="demo"></span> <button onclick='this.innerHTML=Date()'>时间</button> </body> <script type="text/javascript"> </script> </html>
In the above example, the JavaScript code modifies the content of its own element. (Use this.innerHTML).
JavaScript code is usually a few lines of code, and it is more common to call it through event attributes.
Common HTML events
##Events | Description |
## HTML element changes | onclick |
The user clicks on the HTML element | onmouseover |
The user moves the mouse over an HTML element | onmouseout |
The user moves the mouse over an HTML element | onkeydown |
The user presses Press the keyboard key | onload |
The browser has completed loading the page | What can JavaScript events do? Events can be used to handle form validation, user input, user behavior and browser actions:
You can use multiple methods to execute JavaScript event code
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study. For more related tutorials, please visit JavaScript Video Tutorial, jQuery Video Tutorial, bootstrap Tutorial! |
The above is the detailed content of What is the event of JavaScript learning? What are events used for?. For more information, please follow other related articles on the PHP Chinese website!