Basic knowledge of Event Processing in JavaScript

Source: Internet
Author: User
Overview of Event Processing in JavaScript
Event Processing is a very important part of object-oriented programming. without event processing, the program will become very dead and lacks flexibility. The process of event processing can be like this: Event-start event handler-event handler to respond. To enable the event handler to start, you must first tell the object what handler to start if something happens. Otherwise, the process cannot proceed. The event handler can be any JavaScript statement, but we usually use a specific custom function to handle the event.
There are three methods to specify an event handler:
Method 1 is directly specified in the HTML tag. This method is the most common. The method is:
<标记 ... 事件="事件处理程序" [事件="事件处理程序" ...] onload="alert('网页读取完成,请慢慢欣赏!')" onunload="alert('再见!')">

Let's take a look at the example:


Such definitionMark to enable a dialog box to pop up when the document is read, saying "webpage reading is complete, please enjoy it slowly"; when the user exits the document (or closes the window, or goes to another page) "Goodbye" is displayed ".
Method 2: compile the JavaScript code for a specific object event. This method is rarely used, but it is useful in some scenarios. The method is:

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.