This article mainly introduces the event mechanism in JavaScript, that is, the general interaction between JS and HTML, the need for friends can refer to the
What is the event?
JavaScript and HTML interaction are handled by manipulating events that occur on a page in a user or browser.
When the page loads, this is an event. When the user clicks on a button, clatter, which is an event. Another example of an event is similar to pressing any key, closing the window, adjusting the window, and so on.
Developers can use these events to perform JavaScript-encoded responses that cause buttons to close windows, messages to display to users, data to validate, and almost any other type of response that can occur.
Events are level 3rd of the Document Object Model (DOM), and a set of one part of each HTML element can trigger JavaScript code events.
Example:
?
1 2 3 4 5 6 7 8 9 10 11 12 13-14 |
|
This will produce the following results when you click the "Hello" button, and then the occurrence of the onclick event will trigger the SayHello () function.
OnSubmit Event Type:
Another most important type of event is onsubmit. This event is raised when an attempt is submitted to submit a form. Therefore, you can validate the form against this event type.
Here is a simple example of how to use it. Here we call a validate () function before submitting the form data to the Web server. If the form returns true for the Validate () function being committed, the data is not submitted.
Example:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
onMouseOver and onmouseout:
These two event types will help create pictures even with text and good results. When putting the mouse over any element, when moving the mouse out of the element takes place the onmouseout event occurs, the onMouseOver event occurs when the move is obsolete.
Example:
The following example illustrates that the grouped reactions are as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
You can use these two event types to change different images, or you can create a user that helps you.
HTML 4 Standard Event
The standard HTML4 event is listed here for your reference. The following script shows a JavaScript function function to perform on the event.