Event properties in JavaScript

Source: Internet
Author: User
Tags relative

Altkey, Button, cancelbubble, ClientX, ClientY, Ctrlkey, Fromelement, KeyCode, OffsetX, OffsetY, PropertyName, Returnvalu E, ScreenX,

ScreenY, Shiftkey, srcelement, Srcfilter, toelement, type, x, y

1.altKey Description: Check the status of the ALT key.

Syntax: Event.altkey

Possible value: TRUE If the ALT key is pressed, or FALSE. Read-only.

2.button Description: Check the pressed mouse button.

Syntax: Event.button

Possible values: 0 no keys 1 Press left 2 press right key 3 press about Key 4 Press middle Key 5 press left and middle Key 6 press right key and middle Key 7 press all keys

This property is used only for onmousedown, onmouseup, and onmousemove events. For other events, returns 0 (such as onclick), regardless of mouse state.

3.cancelBubble Description: Detects whether to accept control of events for upper-level elements.

Grammar: event.cancelbubble[= cancelbubble]

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

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

Example: The following code fragment shows the SHOWSRC () function that is raised by the event onclick on the upper element (body) If the SHIFT key is also pressed when clicked (onclick) on the picture.

<script type= "Text/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 client area of the window.

Syntax: Event.clientx

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

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

Syntax: Event.clienty

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

6.ctrlKey Description: Check the state of the CTRL key.

Syntax: Event.ctrlkey

Possible value: TRUE If the CTRL key is pressed, or FALSE. Read-only.

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

Syntax: event.fromelement

Note: This is a read-only property.

8.keyCode Description: Detects keyboard events corresponding to the internal code. This property is used for onkeydown, onkeyup, and onkeypress events.

Grammar: event.keycode[= KeyCode]

Possible value: This is a read-write value that can be any Unicode keyboard inner code. If a keyboard event is not raised, the value is 0.

9.offsetX Description: Check the horizontal coordinates of the mouse position relative to the object triggering the event

Syntax: Event.offsetx

10.offsetY Description: Check the vertical coordinates of the mouse position relative to the object triggering the event

Syntax: event.offsety

11.propertyName Description: Sets or returns the name of the changed attribute of the element.

Syntax: event.propertyname [= Sproperty]

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

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

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

12.returnValue Description: Sets or checks the value returned from the event

Syntax: event.returnvalue[= Boolean]

Possible value: True the value in the event is returned false the default action on the event on the source object is canceled

See the example at the beginning of this article.

13.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 get the current position of the mouse through it, but you cannot use it to change the position of the mouse.

14.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 get the current position of the mouse through it, but you cannot use it to change the position of the mouse.

15.shiftKey Description: Check the state of the SHIFT key.

Syntax: Event.shiftkey

Possible value: TRUE If the SHIFT key is pressed, or FALSE. Read-only.

16.srcElement Description: Returns the element that triggers the event. Read-only. Examples are shown at the beginning of this article.

Syntax: event.srcelement

17.srcFilter Description: Returns the filter that triggers the onfilterchange event. Read-only.

Syntax: Event.srcfilter

18.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.

19.type Description: Returns the event name.

Syntax: Event.type

Note: Returns an event name without "on" as the prefix, for example, the type returned by the onclick event is click-only.

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

Syntax: event.x

Note: If the mouse is moved outside the window after the event is triggered, the value returned is-1, which is a read-only property. This means that you can only get the current position of the mouse through it, but you cannot use it to change the position of the mouse.

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

Syntax: EVENT.Y

Note: If the mouse is moved outside the window after the event is triggered, the value returned is-1, which is a read-only property. This means that you can only get the current position of the mouse through it, but you cannot use it to change the position of the mouse.

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.