Window. event object

Source: Internet
Author: User

1. event indicates the event status, such as the element that triggers the event object, the location and status of the mouse, and the key to be pressed. 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.

2. attributes:

Altkey, button, Member, clientx, clienty, ctrlkey, fromelement, keycode, offsetx, offsety, propertyname, returnvalue, screenx, screeny, delimiter, srcelement, srcfilter, toelement, type, X, Y

3. Attribute details:

Attribute name Description Value Description
Altkey Check the status of the Alt key When the Alt key is pressed, the value is true; otherwise, the value is false. Read-Only
Shiftkey Check the Shift key status When the Shift key is pressed, the value is true; otherwise, the value is false. Read-Only
Ctrlkey Check the ctrl key status When the ctrl key is pressed, the value is true; otherwise, the value is false. Read-Only
Example: the status of the Special keys is displayed when you click the button)
<Input type = "button" value = "click" onclick = "showstate ()"/>
<SCRIPT>
Function show (){
Alert ("altkey:" + window. event. altkey
+ "\ Nshiftkey:" + window. event. shiftkey
+ "\ Nctrlkey:" + window. event. ctrlkey );
} </SCRIPT>
Keycode Detect the internal code corresponding to the keyboard event   It can be read and written, and can be any Unicode keyboard internal code. If no keyboard event is triggered, the value is 0.
Example: press the Enter key to make the next component focus. Press the tab key instead)
<Input type = "text" onkeydown = "nextblur ()"/>
<Input type = "text"/>
<SCRIPT>
Function nextblur (){
If (window. event. keycode = 13) // The Return key code
Window. event. keycode = 9; // code of the tab key
}
</SCRIPT>
Srcelement Returns the element of the trigger event. Object Read-Only
Example: (the name value of the button is displayed when you click the button)
<Input type = "button" value = "" name = "Fujian" onclick = "show ()"/>
<Input type = "button" value = "" name = "Jiangxi" onclick = "show ()"/>
<SCRIPT>
Function show (){
Alert (window. event. srcelement. Name );
}
</SCRIPT>
X, Y Position of the mouse relative to the current Browser Px Read-Only
Clientx, clienty The current location of the mouse relative to the webpage Px Read-Only
Offsetx, offsety The current location of the mouse relative to a certain area of the webpage Px Read-Only
Screenx, screeny Position relative to User display Px Read-Only
Note: When you click a button (x, clientx, offsetx, screenx), you can easily understand offsetx. After you restore the IE window, you can obtain (x, clientx, screenx ), you will understand screenx. When you change the position of the DIV property between absolute and relative, you will understand the difference between x and clientx.
Returnvalue Set or check the value returned from the event The value in the true event is returned.
False: the default operation of events on the source object is canceled.
Read/write
For example, right-click shielding, CTRL + N, Shift + F10, F5 refresh, and backspace
Function keydown (){
// Shield right-click, CTRL + N, Shift + F10, F5 refresh, and backspace key
If (window. event. altkey )&&
(Window. event. keycode = 37) | // mask Alt + direction key seek
(Window. event. keycode = 39) {// mask Alt + direction key →
Event. returnvalue = false; // prevents the use of ALT + arrow keys to forward or backward webpages
}
If (event. keycode = 8) | // shield the unregeed deletion key
(Event. keycode = 116) | // block the F5 refresh key
(Event. keycode = 112) | // blocked F1 refresh key bitscn.com China Network Management Alliance
(Event. ctrlkey & event. keycode = 82) {// Ctrl + R
Event. keycode = 0;
Event. returnvalue = false;
}
If (event. ctrlkey) & (event. keycode = 78) // block Ctrl + n
Event. returnvalue = false;
If (event. shiftkey) & (event. keycode = 121) // block SHIFT + F10
Event. returnvalue = false;
If (window. event. srcelement. tagname = "A" & window. event. shiftkey)
Window. event. returnvalue = false; // block shift with the left mouse button to open a new page
If (window. event. altkey) & (window. event. keycode = 115) {// block Alt + F4
Window. showmodelessdialog ("about: blank", "", "dialogwidth: 1px; dialogheight: 1px ");
Return false ;}
}
Button Check the pressed mouse key 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
Only used for onmousedown, onmouseup, and onmousemove events. For other events, no matter the mouse status, 0 (such as onclick) is returned)
Srcelement Detects the elements that the mouse leaves when the onmouseover and onmouseout events occur. Object Read-Only
Toelement Detects the elements that the mouse enters when the onmouseover and onmouseout events occur. Object Read-Only
Type Returned event name   The name of an event without a prefix of "on" is returned. For example, the Type returned by the onclick event is click.

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.