jQuery in Action

124
CHAPTER 4
Events are where it happens!
Man does not live by appetizers alone! How would you go about adding new
sections for entrees, beverages, and desserts? Banana flamb sounds delight-
ful! How would these new sections affect the setup of the JavaScript code?
As diners are selecting (and deselecting) their choices, you could provide a
running total of the order amount. How would you go about keeping track
of the order total?
If the use of custom attributes is not to your liking, refactor the page to
eliminate them. But be sure that the price information remains defined in
one place only!
Perhaps the biggest flaw in the code is that it depends greatly on the posi-
tional relationships of the elements in an appetizer entry. This allowed the
markup to remain simple but at the expense of both creating a strong bind-
ing between the structure of an entry and the supporting code and introduc-
ing complex jQuery selectors. How would you go about making the code
more robust so that changes to the structure of an entry would have less
impact on the code? Adding
CSS
class names to tag the elements (rather
than relying on positional relationships) would be one fine way of accom-
plishing this; how would you go about it? What other ideas do you have?
If you come up with ideas that you're proud of, be sure to visit the Manning web
discussion forum. You're encouraged to post your solutions for all to see and discuss!
4.4 Summary
Building upon the jQuery knowledge that we've gained so far, this chapter intro-
duced us to the world of event handling.
We learned that there are vexing challenges to implementing event handling
in web pages, but such handling is essential for creating pages in Rich Internet
Applications. Not insignificant among those challenges is the fact the there are
three event models that each operate in different ways across the set of modern
popularly used browsers.
The legacy Basic Event Model, also informally termed the
DOM
Level 0 Event
Model, enjoys somewhat browser-independent operation to declare event listen-
ers, but the implementation of the listener functions requires divergent browser-
dependent code. This event model is probably the most familiar to page authors,
and assigns event listeners to
DOM
elements by assigning references to the lis-
tener functions to properties of the elements; the
onclick
property, for example.


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

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