window.event object details

1, event on behalf of the state of events, such as trigger event object element, the location and status of the mouse, press the button and so on. event object only in the course of events to be effective. event of certain attributes only makes sense for specific events. For example, fromElement and toElement attributes onmouseover and onmouseout events are only meaningful.

2, attributes:
altKey, button, cancelBubble, clientX, clientY, ctrlKey, fromElement, keyCode, offsetX, offsetY, propertyName, returnValue, screenX, screenY, shiftKey, srcElement, srcFilter, toElement, type, x, y

3, property details:

Property Name Description Value Description
altKey check the status of alt key is pressed when the alt key, a value of True False otherwise read-only
shiftKey check the status of shift key when the shift key pressed, the value is read only True False otherwise
ctrlKey check the ctrl key pressed state when the ctrl key, a value of True False otherwise read-only cases: (Click the button shows that a few special keys pressed state)
<input type="button" value=" Click on the "/>
<script>
function show () (
alert ("altKey:" + window.event.altKey
+ "\ NshiftKey:" + window.event.shiftKey
+ "\ NctrlKey:" + window.event.ctrlKey);
) </ Script>
keyCode detect keyboard event corresponding to the internal code can read and write, can be any code within a Unicode keyboard. If there is no trigger keyboard events, then the value is 0
Example: (press Enter for the next components are the focus of considerable press Tab key)
<input type="text" onKeyDown="nextBlur()"/>
<input type="text"/>
<script>
function nextBlur () (
if (window.event.keyCode == 13) / / Enter the code
window.event.keyCode = 9; / / Tab key code
)
</ Script>
srcElement return Object element triggered the event read-only cases: (click on the button when the display name value)
<input type="button" value=" Min " name=" Fujian "/>
<input type="button" value=" Gan " name=" Jiangxi "/>
<script>
function show () (
alert (window.event.srcElement.name);
)
</ Script>
x, y relative to the current mouse position px read-only browser
clientX, clientY the current mouse position relative to the page read px
offsetX, offsetY mouse relative to the current page in the location of a region px read-only
screenX, screenY position relative to the user px display read-only Description: When you click a button, get (x, clientX, offsetX, screenX) is easy to understand offsetX; IE window when you obtained by reduction (x, clientX, screenX) , you will understand screenX; When you position the div property to switch between absolute and relative, you will understand the difference between x and clientX.
returnValue set or check the return value from the event in the event the value of true is returned
false the default event source object can read and write operation was canceled example: Shield Right, Ctrl + n, shift + F10, F5 to refresh, backspace
function KeyDown () (
/ / Shield right, Ctrl + N, Shift + F10, F5 to refresh, backspace
if ((window.event.altKey) & &
((Window.event.keyCode == 37) | | / / Alt + arrow key ← shield
(Window.event.keyCode == 39))) (/ / screen Alt + arrow keys →
event.returnValue = false; / / prevent the use of ALT + the arrow keys to page forward or backward
)
if ((event.keyCode == 8) | | / / mask the Backspace key to delete
(Event.keyCode == 116) | | / / shield F5 key to refresh
(Event.keyCode == 112) | | / / screen refresh key bitsCN.com F1 Chinese network alliance
(Event.ctrlKey & & event.keyCode == 82)) (/ / Ctrl + R
event.keyCode = 0;
event.returnValue = false;
)
if ((event.ctrlKey) & & (event.keyCode == 78)) / / screen Ctrl + N
event.returnValue = false;
if ((event.shiftKey) & & (event.keyCode == 121)) / / shield Shift + F10
event.returnValue = false;
if (window.event.srcElement.tagName == "A" & & window.event.shiftKey)
window.event.returnValue = false; / / shielding shift plus the left mouse button to open a new page
if ((window.event.altKey) & & (window.event.keyCode == 115)) (/ / screen Alt + F4
window.showModelessDialog ("about: blank ",""," dialogWidth: 1px; dialogHeight: 1px");
return false;)
)
Press the mouse button check button 0 no key
A left click
2 Press Right
3 left-right
4 Press the middle button
5, left click and the middle button
6, right-click and the middle button
7 by all the key only for onmousedown, onmouseup and onmousemove event. On the other events, no matter how the mouse state, have returned to 0 (such as onclick)
srcElement detection onmouseover and onmouseout event occurs, the mouse is read from the element Object
toElement onmouseover and onmouseout event detection, the mouse is read-only access to the element Object
return back to the event type name is not "on" as the prefix of the event name, for example, onclick event return type is the click

分类:Web 时间:2010-05-30 人气:363
分享到:
blog comments powered by Disqus

相关文章

  • Dynamically change the input type tag attributes (such as the password to text) 2010-12-25

    <HTML> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <script> function removeSubmitFocus () { document.all ('pass'). outerHTML = "<input type = text name ='" + document

  • To input type = "file" can not be edited 2010-08-24

    Today, when doing the project encountered problems uploading text box, <input type="file" size="100" name="photoupload" /> In firefox, the text produced by the control box is the default non-editable, but in IE, this te

  • input type = file against the user to manually enter 2010-07-31

    1. Replace the law Using hidden <input type="file"/> control, then a read-only text box and a button to simulate <input type="file"/> function. <input type="file" name="file" onpropertychange="fi

  • input type = file tag ban the user to manually enter 2010-08-02

    Surface is the method used: 1. Substitution Using hidden <input type="file"/> control, then a read-only text box and a button to simulate <input type="file"/> function. <Input type = "file" name = "file&qu

  • input type description 2010-11-19

    Form Input in the form that an input object, its type and with different sub-Type text input box, the password input box, radio / check box, and submit / reset buttons, the following introduced one by one. 1, type = text Input type is text, this is t

  • input type = "image" input type = "submit" difference 2011-01-09

    input type = "image" input type = "submit" difference input type = "submit" button on the form is submitted, using the system default style, input type = "image" can also submit the form, but the use of user-specifi

  • The input type = "file" empty the contents of the selected file 2011-01-11

    Upload files, select the file path to empty the file two ways: JS code <input type="file" name="file" /> The first one: (display: none can not use) var obj = document.getElementById ('fileupload'); obj.select (); document.execCom

  • Refresh the page to retain the value of input type 2009-06-13

    Transfer from: http://unbounder.javaeye.com/blog/459183 In general, the page refreshes without the need to retain the value of input type are more, but there are exceptions, for example, I it was a case of the need to retain the value of input type .

  • input type = submit or button type = submit 2008-05-16

    http://www.sitepoint.com/forums/showthread.php?t=598656 AutisticCuckoo wrote An <input> button's text is specified in its value attribute, which means it can only be a simple text string. If that's all you need, using an <input> is the way to

  • Use of input type = file 2011-01-14

    From: http://www.hbcms.com/main/dhtml/objects/input_file.html To make a file upload to: INPUT type = file element must appear in the FORM element. Must be INPUT type = file element specifies the NAME attribute value. FORM element method tag attribute

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.448 (s). 12 q(s)