jQuery in Action

Summary
125
Although simple, this model suffers from a you-only-get-one-shot problem;
only one listener can be defined for any event type on a particular
DOM
element.
We can avoid this deficiency by using the
DOM
Level 2 Event Model, a more
advanced and standardized model in which an
API
binds handlers to their event
types and
DOM
elements. Versatile though this model is, it enjoys support only by
standards-compliant browsers such as Firefox, Safari, Camino, and Opera.
For Internet Explorer 6 and 7, an
API
-based proprietary event model that pro-
vides a subset of the functionality of the
DOM
Level 2 Model is available.
Coding all event handling in a series of
if
statements--one clause for the
standard browsers and one for Internet Explorer--is a good way to drive our-
selves to early dementia. Luckily jQuery comes to the rescue and saves us from
that fate.
jQuery provides a general
bind()
command to establish event listeners of any
type on any element, as well as event-specific convenience commands such as
change()
and
click()
. These methods operate in a browser-independent fashion
and normalize the
Event
instance passed to the handlers with the standard prop-
erties and methods most commonly used in event listeners.
jQuery also provides the means to remove event handlers, causes them to be
invoked under script control, and even defines some higher-level commands that
make implementing common event-handling tasks as easy as possible.
We explored a few examples of using events in our pages. In the next chapter,
we'll look at how jQuery builds upon these capabilities to put animation and ani-
mated effects to work for us.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.