Determine the mouse buttons in JS)

Source: Internet
Author: User

IE
The left button is window. event. Button = 1.
Right-click window. event. Button = 2
Window. event. Button = 4
No button action window. event. Button = 0

Firefox
The left button is event. Button = 0.
Right-click event. Button = 2
The key is event. Button = 1.
No button Action event. Button = 0

Opera 7.23/7.54
The left mouse button is window. event. Button = 1.
No button action window. event. Button = 1
Right-click and Middle-click cannot be obtained

Opera 7.60/8.0
The left mouse button is window. event. Button = 0.
No button action window. event. Button = 0
Right-click and Middle-click cannot be obtained

In addition, the right-click window. event. Button = 3 is blocked.

**************************************** ********************

Window. event object represents the event state, such as the elements that trigger the event object, the location and status of the mouse, and the key to press.
Window. Event objects are valid only when an event occurs.
Some Properties of window. event only make sense for specific events. For example, the fromelement and toelement attributes only make sense for onmouseover and onmouseout events.
If the mouse moves out of the window after an event is triggered, the returned value is-1, which 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.

The properties of the event object include:
Altkey, button, Member, clientx, clienty, ctrlkey, fromelement, keycode, offsetx, offsety, propertyname, returnvalue, screenx, screeny, delimiter, srcelement, srcfilter, toelement, type, X, Y

 
The following briefly describes these attributes:
1. altkey
Description: checks the status of the Alt key.
Syntax: event. altkey
Possible value: 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: No buttons; 1: left-click; 2: Right-click; 3: Left and Right; 4: Intermediate; 5: left-click and intermediate; 6: Right-click and intermediate; 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 value: 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.
 
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 value: 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. Refer to 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 value: 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 value: sproperty is a string that specifies or returns the name of the attribute changed by the element that triggers the event.
Note: This attribute can be read and written. No default value. You can use the onpropertychange event to obtain the value of propertyname.
 
12. returnvalue
Description: sets or checks the value returned from the event.
Syntax: event. returnvalue [= Boolean]
Possible value: 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 value: 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. See 7. fromelement
Syntax: event. toelement
Note: This is a read-only attribute.
 
19. Type
Description: The name of the returned event.
Syntax: event. Type
Note: The name of an event without the "on" prefix 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

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.