JS Event Object

Source: Internet
Author: User

Ah, the event also has the object yo. Programmers have been talking about object objects, so, is it time to bring an object home for the new year?
Well, since the event has an object, admit the fact! Haha, then, it has attributes, next, put a

For example, by the way, the commonly used attributes are added.

The event object represents the state of the incident, such as the element in which the event occurred, the state of the keyboard key, the position of the mouse, and the state of the mouse button.

Events are often used in conjunction with functions, and functions are not executed until the event occurs

<! DOCTYPE html>              <script> window.onload = function () {var bt = document.getElementById ("btn");    Bt.onclick = FF;   Bt.onmouseover = FF;   } function ff (EVN) {var di = document.getElementById ("Do"); if (window.event) {EVN = window.event}/* Event object, compatible with IE, event object is an attribute of IE/if (Evn.type = = "click") {/* The custom EVN here is treated as an object, here,   Determine the EVN event object's Operation Event mode */di.innerhtml+= "click<br>";   } else if (Evn.type = = "MouseOver") {di.innerhtml+= "mouseover<br>"; }/* is followed by some of the common properties of the event object */Console.log (Evn.button);/* Event Object Button Property */Console.log (EVN.TYPE);/* Event Object Type Property */Console.log (E   VN.CLIENTX);/* Event Object ClientX Property event occurs when the mouse is positioned relative to the upper-left corner of the viewable document area of the browser window */console.log (evn.clienty);/* Event Object ClientY Properties */   Console.log (EVN.OFFSETX); */* Event Object OffsetX Property event occurs when the mouse is positioned relative to the upper-left corner of the source element */Console.log (evn.offsety);/* Event Object OffsetY Properties */   Console.log (Evn.screenx);/* Event Object ScreenX Property The mouse pointer is positioned relative to the upper-left corner of the display */Console.log (Evn.screeny);/* Event Object ScreenY Properties */ Console.log (evn.target.nodeName);/* The Event Object target property event source is the element where the event occurred; */}</scripT></body>

  

JS Event Object

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.