JavaScript binding events AddEventListener and Attachevent

Source: Internet
Author: User
Tags event listener

1, Eleobj.addeventlistener (eventname,handle,usecapture);

Eleobj:dom elements;

EventName: Event name. Note that the event name here does not have "on", such as mouse click event DoubleClick, mouse double click event, mouse move into event mouseover, mouse move out event mouseout, etc.

Handle: Event handle function, which is the function used to handle the event;

Usecapture:boolean type, whether to use capture, generally with false;

2, Eleobj.attachevent (Eventname,handle);

Eleobj:dom elements;

EventName: Event name. Note that, unlike AddEventListener (), the event name here has "on", such as mouse click event onclick, mouse double click event OnDoubleClick, mouse move into event onmouseover, mouse move out event onmouseout, etc.;

Handle: Event handle function, which is the function used to handle the event;

Note: AddEventListener () is a standard method of binding event listener functions, supported by the publisher, Chrome, FireFox, Opera, Safari, This function is supported by IE9.0 and above, but IE8.0 and the following versions do not support this method, and it uses attachevent () to bind the event listener function. Therefore, this method of binding an event must handle browser compatibility issues.

JavaScript binding events AddEventListener and Attachevent

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.