JS mouse click events in each browser and the event object attribute Introduction _ Basic knowledge
Source: Internet
Author: User
IE Left is Window.event.button = 1
Right key is Window.event.button = 2
The middle key is Window.event.button = 4
No key action Window.event.button = 0
Firefox Left is Event.button = 0
Right key is Event.button = 2
The middle key is Event.button = 1
No key action Event.button = 0
Opera 7.23/7.54 The left mouse button is Window.event.button = 1
No key action Window.event.button = 1
The right and middle keys cannot be obtained
Opera 7.60/8.0 The left mouse button is Window.event.button = 0
No key action Window.event.button = 0
The right and middle keys cannot be obtained
In addition: the right to screen is Window.event.button = 3
The Window.event object represents the state of an event, such as the element that triggers the events object, the position and state of the mouse, the pressed key, and so on.
The Window.event object is valid only if the event occurs.
Some properties of window.event are only meaningful for specific events. For example, the fromelement and toelement attributes are only meaningful for onmouseover and onmouseout events.
If the mouse moves 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.
the properties of the event object have:
Altkey, Button, cancelbubble, ClientX, ClientY, Ctrlkey, Fromelement, KeyCode, OffsetX, OffsetY, PropertyName, Returnvalu E, ScreenX, ScreenY, Shiftkey, srcelement, Srcfilter, toelement, type, x, y
Here's a quick description of these properties:
1.altKey Description: Checks 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 key, 1 left button, 2 right key, 3 press about key, 4 press middle key, 5 left and middle key; 6 press right 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 Boolean value that can be read and write
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.
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: Checks 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 inner 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: Checks the horizontal coordinates of the mouse position relative to the object triggering the event
Syntax: Event.offsetx
10.offsetY Description: Checks 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 property 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.
Note: This property is readable and writable. No default value. You can get the PropertyName value by using the Onpropertychange event.
12.returnValue Description: Sets or checks the value returned from an event
Syntax: event.returnvalue[= Boolean]
Possible value: The value in the true event is returned
False the default action for events on the source object is canceled
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: Checks 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.
X. x 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 moves outside the window after the event is triggered, the value returned is-1
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.
y 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
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.