JavaScript Event Learning Chapter II event browser compatibility _javascript Tips

Source: Internet
Author: User
The events presented here, when they occur on a certain HTML element, can be identified by most browsers. That is, the browser looks for the script for the event handler that you registered for this HTML element, and will be executed immediately.
At first there were only a few events. These events work in almost all JavaScript browsers, even those that are very old. Note that early events can only work on links or forms, and sometimes on the entire window, but not most of the other HTML elements.
Changes in the Times, many new events have been introduced to you. Fourth-generation browsers and more advanced browsers allow events to be registered on any HTML element.
So you can basically tie any event on any element, although it doesn't make sense to tie a keydown to the <P>.
View the complete browser event Compatibility List here.

Interface Event (Interface events)

Interface events are not triggered by user actions, but by user behavior results.
The user clicks on any element to trigger a click time. When a click occurs on an element with special meaning, additional interface events are triggered.
For example, when a user clicks on a link, the click Time is triggered. Click on this link a new page will be loaded, so this particular click event causes the interface event unload to trigger.
Other interface events include Resize,scroll and Focus/blur.

Mouse event (mouse events)

Starting with Netscape 2, all browsers have noticed two of these facts. When the mouse is drawn into a link area, the MouseOver event is triggered. When he clicks on this link then the Click event Triggers. Soon after, Mouseout was added, and he would trigger when the mouse left the link area. Thus the traditional triad of mouse events (traditional Triad) was established.
Third-generation browsers have extended some of the mouse events. Dbclick added in and the Click event was split into MouseDown and MouseUp: The user presses and bounces the mouse button. Last mouse tracker.
The MouseMove of the mark's trajectory has become possible.
The mouse event (mouse event) is explained in detail in later chapters.

Form event (Form events)

The form identifies the submit and reset events, and the trigger triggers the reset when the user submits the form, and triggers when the form is reset. Where the Submit event is the core of all form validation code. When the user submits the form, traverse the form to check for incorrect data. If an error is found, stop submitting the form and issue a warning to the user.
The form can also identify focus and blur events, as well as keyboard events and click events, when a particular item gets or loses the focal point. You can view the other compatibility lists.
Be careful when using these events in general. When a user leaves an item in a form, you can use onblur to validate the data, but this is usually annoying. Users do not want to see any tips when they are busy filling out a form.

The event of the Consortium (the events)

A number of unexpected events (Mutation events) are also defined in the DOM 2 event specification of the consortium. These events are triggered when the DOM structure of the document changes. The most common one is the Domsubtreemodified event, which is triggered when the DOM changes.
Mozilla sets this event to subtreemodified. Mozilla also does not support other events that we have not mentioned.

Microsoft Event (Microsoft events)

Microsoft has created a whole host of events. Some of it is very interesting.
The Comtextmenu event is triggered when the user clicks the right mouse button at any time. This is so useful that it is misused. Mozilla also supports the event.
When importing XML files, the ReadyStateChange event provides services like some load events. When the readystate of an XML document becomes 4, the document is loaded. (Don't ask me what's readystate, he works and he's enough)
Surprisingly, there were beforeunload events before the unload incident. He was designed to cancel the closing of the page, but no one cared.
Finally, Microsoft also invented the MouseEnter and MouseLeave events, which are almost the same as the MouseOver mouseout event. View in the chapter on mouse events.
Of course the above events are only supported by IE.

Mozilla event (Mozilla events)

Mozilla, of course, has a whole host of events of its own. I haven't studied it carefully.

Event handlers

All events will be detected by the browser whenever they are triggered. Browsers typically also perform default programs, just as users click a link. But sometimes nothing happens.

The point of event handlers is that you can make other things happen. You can let the browser execute your script when the event occurs. If you write this, then your script will execute whenever the event occurs. If these scripts can be very useful on a logical basis, your users will also be very happy.

To ensure that your script executes when the event is triggered, you need to register an event with the defined actions of the HTML element, as follows:

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

So alert in the script (' I\ ' ve been clicked! ') will be executed when the Click event occurs. This registers an event handler.

Go on

If you want to continue to study, please read the next chapter.

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.