An analysis of the event mechanism in JavaScript

Source: Internet
Author: User
Tags object model

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.

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.