Java Reference
In-Depth Information
This code assigns the handle() function to handle the <p/> element's dblclick event. When the
function executes, it gets the type of event that caused the handle() function's execution. Because the
event object is global, there is no need to pass the object to the handling function like the DOM event
model. Also note that like other properties of the window object, it's not required that you precede the
event object with window.
The same holds true when you assign event handlers through JavaScript using object properties.
<p id=”p”>Paragraph</p>
<h1 id=”h1”>Heading 1</h1>
<span id=”span”>Special Text</span>
<script type=”text/javascript”>
function handle()
{
if (event.type == “mouseover”)
{
alert(“You moved over the Special Text”);
}
}
document.getElementById(“p”).ondblclick = handle;
document.getElementById(“h1”).onclick = handle;
document.getElementById(“span”).onmouseover = handle;
</script>
Using Event Data
As you can see, IE's event object is straightforward and simple to use; however, it does provide differ-
ent properties from the DOM standard's Event and MouseEvent objects, although they typically pro-
vide you with similar data.
The following table lists some of the properties of IE's event object.
Properties of the
event Object
Description
altKey
Indicates whether the Alt key was pressed when the event was generated.
button
Indicates which button on the mouse was pressed.
cancelBubble
Gets or sets whether the current event should bubble up the hierarchy of
event handlers.
clientX
Indicates where in the browser window, in horizontal coordinates, the
mouse pointer was when the event was generated.
clientY
Indicates where in the browser window, in vertical coordinates, the mouse
pointer was when the event was generated.
ctrlKey
Indicates whether the Ctrl key was pressed when the event was generated.
fromElement
Gets the element object the mouse pointer is exiting.
Search WWH ::




Custom Search