JS event object, simple description

Source: Internet
Author: User

Event indicates the Event status, such as the Event element, keyboard status, mouse position, and mouse button status. Once an Event occurs, an event object is generated. If you click a button, the corresponding Event object is generated in the browser memory.
The event object is valid only when an event occurs.
Some Properties of the event only make sense for specific events. For example, the fromElement and toElement attributes only make sense for onmouseover and onmouseout events.

[Event attribute ]:
AltKey, button, Member, clientX, clientY, ctrlKey, fromElement, keyCode, offsetX, offsetY, propertyName, returnValue, screenX, screenY, delimiter, srcElement, srcFilter, toElement, type, x, y

--------------------------------------------------------------------------------

1. altKey
Description: checks the status of the alt key.

Syntax: event. altKey

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


2. button
Description: checks the pressed mouse key.

Syntax: event. button

Possible values:
0 without buttons
1 left click
2. Right-click
3. Press the Left or Right key.
4. Press the intermediate key
5. Press the left and intermediate keys.
6. Right-click and select intermediate key.
7. Press all keys

This attribute is only used for onmousedown, onmouseup, and onmousemove events. For other events, 0 (such as onclick) is returned regardless of the mouse status ).

 

3. cancelBubble
Description: checks whether events of upper-layer elements are controlled.

Syntax:
Event. cancelBubble [= cancelBubble]

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

TRUE is not controlled by the event of the parent layer.
FALSE allows the event to be controlled by the upper-layer element. This is the default value.

Example:
The following code snippet demonstrates how to cancel showSrc () triggered by event onclick on the upper-Layer Element (body) if the shift key is also pressed when you click onclick on the image () function.

<Script language = "JScript">
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 attribute. This means that you can only use it to get the current position of the mouse, 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 attribute. This means that you can only use it to get the current position of the mouse, but you cannot use it to change the position of the mouse.


6. ctrlKey
Description: checks the status of the ctrl key.

Syntax: event. ctrlKey

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


7. fromElement
Description: 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 attribute.


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

Syntax: event. keyCode [= keyCode]

Possible values:
This is a readable value and can be any Unicode keyboard internal code. If no keyboard event is triggered, the value is 0.


9. offsetX
Description: checks the horizontal coordinates of the mouse position relative to the trigger event object.

Syntax: event. offsetX


10. offsetY
Description: checks the vertical coordinates of the mouse position relative to the trigger event object.

Syntax: event. offsetY


11. propertyName
Description: sets or returns the name of a variable attribute of an element.

Syntax: event. propertyName [= sProperty]

Possible values:
SProperty is a string that specifies or returns the name of the attribute changed by the element that triggers the event.
This attribute can be read and written. No default value.

Note:
You can use the onpropertychange event to obtain the value of propertyName.

Example:
The following example uses the onpropertychange event to display the value of propertyName in a dialog box.

<HEAD>
<SCRIPT>
Function changeProp ()
{
BtnProp. value = "This is the new VALUE ";
}

Function changeCSSProp ()
{
BtnStyleProp. style. backgroundColor = "aqua ";
}
</SCRIPT>
</HEAD>
<BODY>
<P> The event object property propertyName is
Used here to return which property has been
Altered. </P>

<Input type = button ID = btnProp onclick = "changeProp ()"
VALUE = "Click to change the VALUE property of this button"
Onpropertychange = 'alert (event. propertyName + "property has changed value") '>
<Input type = button ID = btnStyleProp
Onclick = "changeCSSProp ()"
VALUE = "Click to change the CSS backgroundColor property of this button"
Onpropertychange = 'alert (event. propertyName + "property has changed value") '>
</BODY>


12. 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 operation of events on the source object is canceled.


13. screenX
Description: horizontal position of the mouse relative to the user's screen.

Syntax: event. screenX

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


14. screenY
Description: the vertical position of the mouse relative to the user's screen.

Syntax: event. screenY

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


15. shiftKey
Description: checks the status of the shift key.

Syntax: event. shiftKey

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


16. srcElement
Description: Elements of the trigger event. Read-only. For examples, see 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: The element that the mouse enters when the onmouseover and onmouseout events occur.

Syntax: event. toElement

Note:
This is a read-only attribute.

Example: The following code shows a dialog box that displays "mouse arrived" when you move the mouse over the button"

<SCRIPT>
Function testMouse (oObject ){
If (oObject. contains (event. toElement ))

{
Alert ("mouse arrived ");
}
}
</SCRIPT>
:
<Button id = oButton onmouseover = "testMouse (this)"> Mouse Over This. </BUTTON>


19. type
Description: The name of the returned event.

Syntax: event. type

Note:
The name of an event without a prefix of "on" is returned. For example, the type returned by the onclick event is click.
Read-only.


20. x
Description: returns the X axis coordinate of the upper-level element of the position attribute relative to the css attribute. If there is no upper-level element with the position attribute in the css attribute, the BODY element is used as the reference object by default.

Syntax: event. x

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


21. y
Description: returns the Y axis coordinate of the parent element of the position attribute relative to the css attribute. If there is no upper-level element with the position attribute in the css attribute, the BODY element is used as the reference object by default.

Syntax: event. y

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

Author: "forgetallaboutyou"
 

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.