The event object for JavaScript

Source: Internet
Author: User

Note: The following is a description of event events under IE, if the application may have compatibility problems under non-IE, it is necessary to use compatibility function to deal with the specific application environment.

1.Altkey

Description: Checks the state of the ALT key.

Syntax: Event.altkey

Possible values: When the ALT key is pressed, the value is TRUE, otherwise FALSE. Read-only.

2.button

Description: Check the mouse button that was pressed.

Syntax: Event.button

Possible values:

0 No keys 1 Press left Button 2 Press right 3 press the left or the right key 4 press the middle key

5 press left and middle Key 6 press right and middle Key 7 press all keys

This property is only used for onmousedown,onmouseup, and onmousemove events. Returns 0 (for example, onclick) for other events, regardless of mouse state.

3.cancelbubble

Description: Detects whether to accept control over events of the upper element.

Syntax: event.cancelbubble[= cancelbubble]

Possible values: This is a read-write Boolean value:

TRUE is not controlled by the upper primitive's events.

FALSE allows events to be controlled by the upper element. This is the default value.

The following code snippet shows the SHOWSRC () function that is thrown by the event onclick on the upper element (body) If the SHIFT key is pressed at the same time when clicking on the image (onclick).

<script LANGUAGE = "JAVASCRIPT" >function Checkcancel () {    if (Window.event.shiftKey)    Window.event.cancelBubble = true;} function Showsrc () {    if (Window.event.srcElement.tagName = = "IMG")    alert (WINDOW.EVENT.SRCELEMENT.SRC);} </script><body onclick= "showsrc ()" > ...

4.ClientX

Description: Returns the x-coordinate of the mouse in the window client area.

Syntax: Event.clientx

Note: This is a read-only property. This means that you can only use it to get the current position of the mouse, but it cannot be used to change the position of the mouse.

5.ClientY

Description: Returns the y-coordinate of the mouse in the window client area.

Syntax: Event.clienty

Note: This is a read-only property. This means that you can only use it to get the current position of the mouse, but it cannot be used to change the position of the mouse.

6.Ctrlkey

Description: Checks the state of the CTRL key.

Syntax: Event.ctrlkey

Possible values:

When the CTRL key is pressed, the value is TRUE, otherwise FALSE. Read-only.

7.Fromelement

Description: Detects onmouseover and onmouseout events that occur when the mouse leaves the element. Reference: 18.toElement

Syntax: event.fromelement

Note: This is a read-only property.

8.KeyCode

Description: Detects the internal code corresponding to the keyboard event.

This property is used for Onkeydown,onkeyup, and onkeypress events.

Syntax: event.keycode[=keycode]

Possible values: This is a read-write value, which can be any Unicode keyboard inside code. If no keyboard event is raised, the value is 0.

9.OffsetX

Description: Checks the horizontal coordinates of the mouse position relative to the object that triggered the event.

Grammar:

Event.offsetx

Ten.OffsetY

Description: Check the vertical coordinates of the mouse position relative to the object that triggered the event

Syntax: event.offsety

PropertyName .

Description: Sets or returns the name of the property that changed the element.

Syntax: event.propertyname[= Sproperty]

Possible value: Sproperty is a string that specifies or returns the name of the property that has changed in the event of the element that triggered the event. This property is readable and writable. No default value.

Note: You can get the value of PropertyName by using the Onpropertychange event.

returnvalue .

Description: Sets or checks the value returned from the event

Syntax: event.returnvalue[= Boolean]

Possible values: The value in the true event is returned

False the default action for events on the source object is canceled

ScreenX .

Description: Detects the horizontal position of the mouse relative to the user's screen

Syntax: Event.screenx

Note: This is a read-only property. This means that you can only use it to get the current position of the mouse, but it cannot be used to change the position of the mouse.

ScreenY .

Description: Detects the vertical position of the mouse relative to the user's screen

Syntax: Event.screeny

Note: This is a read-only property. This means that you can only use it to get the current position of the mouse, but it cannot be used to change the position of the mouse.

Shiftkey .

Description: Checks the state of the SHIFT key.

Syntax: Event.shiftkey

Possible values: When the SHIFT key is pressed, the value is TRUE, otherwise FALSE. Read-only.

srcelement .

Description: Returns the element that triggered the event. Read-only. See the beginning of this article for examples.

Syntax: event.srcelement ( for IE )

srcfilter .

Describe:

Returns the filter that triggered the onfilterchange event. Read-only.

Grammar:

Event.srcfilter

toelement .

Description: Detects the elements that the mouse enters when the onmouseover and onmouseout events occur. Reference: 7.fromElement

Syntax: event.toelement

Note: This is a read-only property.

.Type

Description: Returns the event name.

Syntax: Event.type

Note: Returns an event name that does not have "on" as the prefix, for example, the type returned by the OnClick event is click Read-only.

X. x

Description: Returns the x-coordinate of the mouse relative to the ancestor element with the Position property in the CSS property. If there is no ancestor element with the Position property in the CSS property, the BODY element is used as the reference object by default.

Syntax: event.x

Note: If the mouse moves out of the window after the event is triggered, the value returned is 1-this is a read-only property. This means that you can only use it to get the current position of the mouse, but it cannot be used to change the position of the mouse.

. y

Description: Returns the y-coordinate of the mouse relative to the ancestor element with the Position property in the CSS property. If there is no ancestor element with the Position property in the CSS property, the BODY element is used as the reference object by default.

Syntax: EVENT.Y

Note: If the mouse moves out of the window after the event is triggered, the value returned is 1-this is a read-only property. This means that you can only use it to get the current position of the mouse, but it cannot be used to change the position of the mouse.

The event object for JavaScript

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.