| |
Chapter 3
Dynamic HTML Event Model
Events are notifications that occur as a result of user actions or state
changes within a document or window. Dynamic HTML exposes a set of events
that allows the Web author to respond to most interactions between the user
and the document. By responding to events, the author can create
completely interactive pages.
In this chapter, you'll be introduced to techniques for handling
events. The chapter concludes by demonstrating an application that combines
the built-in support features of Dynamic HTML with the power of JavaScript
function pointers to create a customized event binding mechanism.
The following topics are covered in this chapter:
- General event
model Dynamic HTML provides a powerful event model that is closely related to the document's underlying
structure. By understanding and taking advantage of this model, you can write efficient, maintainable code. The Dynamic HTML
event model is based on two powerful new features for controlling
the document's behavior: event bubbling and
default actions.
Event bubbling is the event model feature that observes the document's structural hierarchy in the processing of event notifications. All events can be responded to by each parent
element in the containership hierarchy as well as by the element
the event occurred within. In other words, every action occurs on
the element, its parent element, and so on until the body and
eventually the document itself receive the event notification. The
event can be processed at each level, enabling you to write compact
generic code.
Default actions represent the browsers' built-in handling of the event. Many events allow the default action to be overridden for custom handling or to be augmented with complementary processing.
Understanding the event model is crucial to understanding
how to harness the power of Dynamic HTML to create interactive
documents. This section introduces the event architecture; later
chapters will cover techniques and operations in detail.
- Event
binding Event binding is the association of a script with
an event on the document or window, or with an event on an
element in the document. This section discusses the different
techniques available in Dynamic HTML for binding scripts to events.
- The
event object The event object exposes the information
related to an event to the script. The
event object is a language-independent mechanism for passing parameters and for controlling different
aspects of the event model. For example, on a mouse event, the
current mouse location and button state information are
exposed through properties of the event object.
- Programming standard user
events Standard user events include the mouse, keyboard, focus, and help events that are available
on almost every element in the document. This section introduces
the interactions between these events and the
event object. Additional events are supported by certain elements and objects and are
discussed throughout this book with their respective objects.
- Event
examples The chapter concludes with two examples
of event binding. The first example consists of an Event Tutor that
can be used to learn about the event model. In this example, events
on a document can be tracked individually or as a group. The
second example, Event Broadcaster, is a powerful demonstration
of JavaScript function pointers and events. In this example,
you'll learn how to write a custom event-binding mechanism that
allows multiple functions to be easily associated with a single event.
[Содержание]
|