JS native future element listening notation

Source: Internet
Author: User
Tags event listener

Another way to bind an event is to use AddEventListener () or attachevent () to bind the event listener function.

AddEventListener () function syntax:
Elementobject.addeventlistener (eventname,handle,usecapture);

Parameters Description
Elementobject A DOM object (that is, a DOM element).
EventName

The event name. Note that the event name here does not have "on",

Like mouse click events click, mouse double click event DoubleClick,

The mouse moves into the event mouseover, the mouse moves out the event mouseout and so on.

Handle The event handle function, which is the function used to handle the event.
Usecapture

Boolean type, whether capture is used, general use false

。 This involves the concept of JavaScript event flow, which will be explained in detail in subsequent chapters.


Attachevent () function syntax:
Elementobject.attachevent (Eventname,handle);

Parameters Description
Elementobject A DOM object (that is, a DOM element).
EventName

The 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 The event handle function, which is the function used to handle the event.


Note: The event handle function refers to "function name" and cannot be enclosed with parentheses.

AddEventListener () is the standard method of binding event listener functions, supported by the consortium, 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.

JS native future element listening notation

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.