EN
Dieser Inhalt ist in Ihrer Sprache leider nicht verfügbar. Im Folgenden finden Sie die englische Version.

event object

Represents the state of an event, such as the element in which the event occurred, the state of the keyboard keys, the location of the mouse, and the state of the mouse buttons.

Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5

 

Members

The event object has these types of members:

Properties

The event object has these properties.

PropertyDescription

actionURL

Gets the URL of a Jump List item that is removed.

This property is not supported for Windows Store apps using JavaScript.

altKey

Gets a value that indicates whether the Alt key is pressed.

altKey

Retrieves a value that indicates the state of the ALT key. For the standards based property, see altKey.

altLeft

Retrieves a value that indicates the state of the left ALT key.

button

Sets or retrieves the mouse button pressed by the user.

This property is not supported for Windows Store apps using JavaScript. For the standards based property that can be used with Windows Store apps using JavaScript , see button.

buttonID

Gets the Thumbnail Toolbar button ID that is clicked.

This property is not supported for Windows Store apps using JavaScript.

cancelBubble

Sets or retrieves whether the current event should bubble up the hierarchy of event handlers.

clientX

Sets or retrieves the x-coordinate of the mouse pointer, or user's finger, position relative to the client area of the window, excluding window decorations and scroll bars. For the standards based property, see clientX.

clientY

Sets or retrieves the y-coordinate of the mouse pointer, or user's finger, position relative to the client area of the window, excluding window decorations and scroll bars.

constructor

Returns a reference to the constructor of an object.

contentOverflow

Retrieves a value that indicates whether the document contains additional content after processing the current LayoutRect object.

ctrlKey

Gets a value that indicates whether the Ctrl key is pressed.

ctrlKey

Sets or retrieves the state of the CTRL key. For the standards based property, see ctrlKey.

ctrlLeft

Sets or retrieves the state of the left CTRL key.

data

Sets or retrieves the body of the onmessage request.

dataFld

Sets or retrieves the data column affected by the oncellchange event.

fromElement

Sets or retrieves the object from which activation or the mouse pointer is exiting during the event.

keyCode

Sets or retrieves the Unicode key code associated with the key that caused the event.

nextPage

Retrieves the position of the next page within a print template.

offsetX

Sets or retrieves the x-coordinate of a pointer's position relative to the object firing the event.

offsetY

Sets or retrieves the y-coordinate of a pointer's position relative to the object firing the event.

origin

Sets or retrieves the scheme, hostname, and port of the document that fired the onmessage event.

propertyName

Sets or retrieves the name of the property that changes on the object.

reason

Sets or retrieves the result of the data transfer for a data source object.

recordset

Sets or retrieves from a data source object a reference to the default record set.

repeat

Retrieves whether the onkeydown event is being repeated. For the standards based property, see repeat.

returnValue

Sets or retrieves the return value from the event.

saveType

Retrieves the clipboard type when oncontentsave fires.

screenX

Sets or retrieves the x-coordinate of the mouse pointer's position relative to the user's screen. For the standards based property, see screenX.

screenY

Sets or retrieves the y-coordinate of the mouse pointer's position relative to the user's screen. For the standards based property, see screenY.

shiftKey

Retrieves the state of the SHIFT key. For the standards based property, see shiftKey.

shiftLeft

Retrieves the state of the left SHIFT key.

source

Retrieves the source window object of the onmessage event.

srcElement

Sets or retrieves the object that fired the event.

srcFilter

Sets or retrieves the filter object that caused the onfilterchange event to fire.

srcUrn

Retrieves the URN of the behavior that fired the event.

toElement

Sets or retrieves a reference to the object toward which the user is moving the mouse pointer or, for a touch device, a finger.

type

Sets or retrieves the event name from the event object.

url

Sets or retrieves the fully qualified URL of the document that fired the event.

wheelDelta

Retrieves the distance and direction the wheel button has rolled.

x

Sets or retrieves the x-coordinate (in pixels) of the mouse pointer, or user's finger, offset from the closest relatively positioned parent element of the element that fired the event.

y

Sets or retrieves the y-coordinate (in pixels) of the mouse pointer, or user's finger, offset from the closest relatively positioned parent element of the element that fired the event.

 

Standards information

Remarks

The event object is available only during an event—that is, you can use it in event handlers but not in other code.

Although all event properties are available to all event objects, some properties might not have meaningful values during some events. For example, the fromElement and toElement properties are meaningful only when processing the onmouseover and onmouseout events.

In Microsoft Visual Basic Scripting Edition (VBScript), you must access the event object through the window object.

Several of the properties that apply to this object are not writable unless this object has been created using the createEventObject method. The following is a list of these properties: altKey, altLeft, button, clientX, clientY, ctrlKey, ctrlLeft, dataFld, offsetX, offsetY, propertyName, qualifier, reason, repeat, screenX, screenY, shiftKey, shiftLeft, srcUrn, type, x, and y.

Examples

This example uses the event object to check whether the user clicked the mouse within a link, and to prevent the link from being navigated if the SHIFT key is down. It also display mouse position within the <body> element:


<!DOCTYPE html>
<html>

<head>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <title>Cancels Links</title>
  <style>
    body {
      border: 1px black solid;
      width: 32em;
      padding: 0 1em;
    }
  </style>
</head>

<body id="bodyTag">
  <p>Mouse over this black box (i.e., the &lt;body&gt; element) to see mouse 
  position.
  <p>And click <a href="http://www.bing.com" target="_blank">this</a> link with and without holding the SHIFT key down.</p>
  <p id="mousePositionDisplay">Mouse position:</p>
  <script>
    var bodyElement = document.getElementById('bodyTag');
    bodyElement.addEventListener('click', cancelLink, 'false');
    bodyElement.addEventListener('mousemove', reportMousePosition, 'false');
     
    function cancelLink() {
      if (window.event.srcElement.tagName == "A" && window.event.shiftKey) {
        window.event.returnValue = false;
      }
    }
    
    function reportMousePosition() {
      document.getElementById('mousePositionDisplay').innerHTML = "Mouse position: (" + window.event.x + ", " + window.event.y + ")";
    }
  </script>
</body>

</html>

 

 

Anzeigen:
© 2014 Microsoft