JavaScript Event Learning Chapter 2: Event

Source: Internet
Author: User

In this chapter, I will give an overview of important events, including compatibility issues with some popular browsers.

The events proposed here, when they happen on a fixed HTML element, their names can be recognized by most browsers. That is to say, the browser will find the event handler script you have registered for this HTML element, and it will be executed immediately.
At first, there were only a few events. These events can run in almost all JavaScript browsers, even those very old. Note that early events can only work on links or forms, and sometimes run on the entire window, but most other HTML elements cannot.
The times have changed and many new events have been introduced to you. The fourth-generation browser and more advanced browser allow events to be registered on any HTML element.
Therefore, you can basically bind any event on any element, although binding a keydown on <P> makes no sense.
View the complete browser event compatibility list here.

Interface events)
Interface events are not triggered by user actions, but are triggered by user behavior results.
Clicking on any element triggers a click Time. When a click occurs on an element with a special meaning, an additional interface event is triggered.
For example, when you click a link, the click Time is triggered. Clicking this link on a new page will be loaded, so this special click event triggers the interface event unload.
Other interface events include resize, scroll, and focus/blur.

Mouse events)
Since Netscape 2, all browsers have noticed these two facts. When you move the cursor to a link area, the mouseover event is triggered. When he clicks this link, the click event is triggered. Soon after, mouseout was added, which will be triggered when the mouse leaves the link area. Therefore, Traditional Triad was established.
Third-generation browsers expand mouse events. When dbclick is added, the click event is divided into mousedown and mouseup: the user presses and plays the mouse button. Last Tracker
The mousemove of the standard track is also possible.
The mouse event will be detailed in later sections ).

Form events)
The form can recognize the submit and reset events. The submit triggers the reset when the user submits the form and triggers the reset form. The submit event is the core of All Form Verification code. When a user submits a form, the user traverses the form to check whether there is any incorrect data. If an error is found, stop submitting the form and send a warning to the user.
The form can also identify the focus and blur events when one item gets or loses focus, as well as Keyboard Events and click events. You can view other compatibility lists.
Be careful when using these events. You can use onblur to verify data when you leave an item in the form, but this is usually annoying. The user does not want to see any pop-up prompts when filling out the form.

W3C event (W3C events)
Some Mutation events are also defined in the W3C DOM 2 event specification ). These events are triggered when the DOM structure of the document changes. The most common event is the DOMSubtreeModified event, which is triggered when the DOM changes.
Mozilla sets this event as subtreemodified. Mozilla does not support other w3c events that we did not mention.

Microsoft events)
Microsoft has created many events. Some of them are very interesting.
The comtextmenu event will be triggered when you right-click it at any time. This is very useful and abused. Mozilla also supports this event.
When importing XML files, the readystatechange event provides services like some load events. When the readyState of the XML file is changed to 4, the file is loaded. (Don't ask me what readyState is. It works and is enough)
What's surprising is that there were beforeunload events before the unload event. He designed to Cancel Page closure, but nobody cares.
Finally, Microsoft invented the mouseenter and mouseleave events, which are almost the same as the mouseover and mouseout events. In the mouse event chapter, view.
Of course, the above events are only supported by IE.

Mozilla event (Mozilla events)
Mozilla, of course, has a lot of its own events. I have not studied it carefully.

Event Handler
All events are detected by the browser at any time. Browsers usually execute Default Programs, just as when users click a link. But sometimes nothing happens.

The focus of the event handler is that you can make other things happen. You can let the browser execute your script when an event occurs. If you write this statement, your script will be executed whenever an event occurs. If these scripts are very useful on a logical basis, your users will be very happy.

To ensure that your script can be executed when an event is triggered, You need to register an event for the identified action of the HTML element, as shown below:

<A href = "somewhere.html" onClick = "alert ('I \ 've been clicked! ') ">

In this way, the alert ('I \' ve been clicked! ') Will be executed when the click event occurs. This registers an event handler.

If you want to continue learning, please refer to the next chapter.

Address: http://www.quirksmode.org/js/events_events.html

Author: Beiyu (tw: @ rehawk)
Article Source: http://beiyu.cnblogs.com

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.