Discussion on Event binding between IE and FF

Source: Internet
Author: User

Event binding: There are five types of events:
1. bind to an elementThis is also a common example:
<Input type = "button" onclick = "doeventthing (event)">
In this way, we bind doeventthing to the button object and click this button to trigger the event.
2. Bind events to objects: This is also a common one, especially under ie4 +:
Document. getelementbyid ("divid"). onclick = doeventthing;
3. Use <script for> to bind eventsThis is only useful in ie4 + (BIND events for buttong1, and the logic writes events in the script block to specify how to trigger events ):

<SCRIPT event = "onclick" for = "button1">
// Script statements here

4. Use the attachevent () method of ie5/Windows
5. Use the addeventlistener () method of W3C dom
Addeventlistener ("eventtype", listenerreference, captureflag );
The third parameter is a Boolean value indicating whether the node listens for events in the so-called capture mode in the Dom. For a typical event listener, the third parameter should be false ).
Prototype is compatible with IE and W3C when binding events as follows:

_ Observeandcache: function (element, name, observer, usecapture) {If (! This. observers) This. observers = []; If (element. addeventlistener) {// W3C Dom this. observers. push ([element, name, observer, usecapture]); element. addeventlistener (name, observer, usecapture);} else if (element. attachevent) {// ie5/Windows this. observers. push ([element, name, observer, usecapture]); element. attachevent ('on' + name, observer );}}

Aside from this. Observers. pust ([element, name, observer, usecapture]), we will be very clear about binding events 4 and 5. We know that the usecapture of this prototype method does not work in IE. It only works for W3C event processing mechanism.

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.