JavaScript & jQuery- The Missing Manual, 3rd Edition.pdf

(23147 KB) Pobierz
“The Missing Manual series is simply the most intelligent and usable series of guidebooks…”
JavaScript
& jQuery
rd Edition
3
Covers
jQuery UI
—KEVIN KELLY, CO-FOUNDER OF
WIRED
David Sawyer McFarland
Answers found here!
JavaScript lets you supercharge your web pages with
animation, interactivity, and visual effects, but learning the
language isn’t easy. This fully updated and expanded guide
takes you step-by-step through JavaScript basics, then
shows you how to save time and effort with jQuery—the
library of prewritten JavaScript code—and the newest
innovations from the jQuery UI plug-in.
David Sawyer McFarland,
president of Sawyer
McFarland Media, Inc.,
has spent nearly 20 years
building and managing
websites. Having served
as webmaster at UC
Berkeley, he’s also taught
at the UC Berkeley
Graduate School of
Journalism and the
Portland State University
multimedia program.
David lives in Portland
and has written
bestselling Missing Manual
titles on Adobe
Dreamweaver and CSS
The important stuff you need to know
n
Make your pages come alive.
Use jQuery to create interactive
elements that respond to visitor input.
Get acquainted with jQuery UI.
Expand your interface with
tabbed panels, dialog boxes, date pickers, and other widgets.
Display good forms.
Get information from visitors, help
shoppers buy goods, and let members post their thoughts.
Go beyond the browser with Ajax.
Communicate with the
web server to update your pages without reloading.
Put your new skills right to work.
Create a simple application
step-by-step, using jQuery and jQuery UI widgets.
Dive into advanced concepts.
Use ThemeRoller to customize
your widgets; avoid common errors that new programmers
often make.
n
n
n
n
n
Web Authoring and Design
US $49.99
CAN $52.99
ISBN: 978-1-491-94707-4
missingmanuals.com
twitter: @missingmanuals
facebook.com/MissingManuals
JavaScript
& jQuery
The book that should have been in the box®
David Sawyer McFarland
Beijing | Cambridge | Farnham | Köln | Sebastopol | Tokyo
JavaScript & jQuery: The Missing Manual
by David Sawyer McFarland
Copyright © 2014 Sawyer McFarland Media, Inc. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc.,
1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://safaribooksonline.com). For
more information, contact our corporate/institutional sales department: (800) 998-
9938 or
corporate@oreilly.com.
July 2008:
First Edition.
October 2011:
Second Edition.
September 2014: Third Edition.
Revision History for the Third Edition:
2014-09-10
First release
See
http://oreilly.com/catalog/errata.csp?isbn=9781491947074
for release details.
The Missing Manual is a registered trademark of O’Reilly Media, Inc. The Missing
Manual logo, and “The book that should have been in the box” are trademarks of
O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to
distinguish their products are claimed as trademarks. Where those designations
appear in this book, and O’Reilly Media is aware of a trademark claim, the
designations are capitalized.
While every precaution has been taken in the preparation of this book, the publisher
assumes no responsibility for errors or omissions, or for damages resulting from the
use of the information contained in it.
ISBN-13: 978-1-491-94707-4
[LSI]
Contents
The Missing Credits
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ix
Introduction
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xiii
What Is JavaScript? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
What Is jQuery? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
HTML: The Barebones Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
CSS: Adding Style to Web Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Software for JavaScript Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
The Very Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi
About the Online Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii
Part One:
Getting Started with JavaScript
CHAPTER 1:
Writing Your First JavaScript Program
. . . . . . . . . . . . . . . . . . . . .
3
Introducing Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
How to Add JavaScript to a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Your First JavaScript Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Writing Text on a Web Page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Attaching an External JavaScript File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Tracking Down Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
CHAPTER 2:
The Grammar of JavaScript
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Built-In Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Types of Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
Working with Data Types and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Tutorial: Using Variables to Create Messages . . . . . . . . . . . . . . . . . . . . . . . . . 40
Tutorial: Asking for Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
Tutorial: Writing to a Web Page Using Arrays . . . . . . . . . . . . . . . . . . . . . . . . . 51
A Quick Object Lesson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58
iii
Zgłoś jeśli naruszono regulamin