Resig - Pro JavaScript Techniques (Apress, 2006).pdf

(5968 KB) Pobierz
19073135 UNPDF
THE EXPERT’S VOICE ® IN WEB DEVELOPMENT
JavaScript
Techniques
Real-world JavaScript techniques for
the modern, professional web developer
John Resig
Pro
19073135.040.png 19073135.050.png 19073135.060.png 19073135.070.png 19073135.001.png 19073135.002.png 19073135.003.png 19073135.004.png 19073135.005.png 19073135.006.png 19073135.007.png 19073135.008.png 19073135.009.png 19073135.010.png 19073135.011.png 19073135.012.png 19073135.013.png 19073135.014.png 19073135.015.png 19073135.016.png 19073135.017.png 19073135.018.png 19073135.019.png
 
19073135.020.png
 
19073135.021.png
 
19073135.022.png
 
19073135.023.png
 
19073135.024.png 19073135.025.png 19073135.026.png 19073135.027.png 19073135.028.png 19073135.029.png 19073135.030.png 19073135.031.png 19073135.032.png 19073135.033.png 19073135.034.png
 
19073135.035.png 19073135.036.png 19073135.037.png 19073135.038.png 19073135.039.png 19073135.041.png 19073135.042.png 19073135.043.png 19073135.044.png 19073135.045.png 19073135.046.png 19073135.047.png 19073135.048.png 19073135.049.png 19073135.051.png 19073135.052.png 19073135.053.png 19073135.054.png 19073135.055.png 19073135.056.png 19073135.057.png 19073135.058.png 19073135.059.png 19073135.061.png 19073135.062.png 19073135.063.png 19073135.064.png 19073135.065.png 19073135.066.png 19073135.067.png
Pro JavaScript
Techniques
John Resig
19073135.068.png 19073135.069.png 19073135.071.png
Pro JavaScript™ Techniques
Copyright © 2006 by John Resig
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-59059-727-9
ISBN-10 (pbk): 1-59059-727-3
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the
US and other countries. Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was writ-
ten without endorsement from Sun Microsystems, Inc.
Lead Editor: Chris Mills
Technical Reviewer: Dan Webb
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick,
Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser,
Keir Thomas, Matt Wade
Project Manager: Tracy Brown Collins
Copy Edit Manager: Nicole Flores
Copy Editor: Jennifer Whipple
Assistant Production Director: Kari Brooks-Copony
Production Editor: Laura Esterman
Compositor: Linda Weidemann, Wolf Creek Press
Proofreader: April Eddy
Indexer: Broccoli Information Management
Artist: April Milne
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com ,
or visit http://www.springeronline.com .
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley,
CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com , or visit http://www.apress.com .
The information in this book is distributed on an “as is” basis, without warranty. Although every pre-
caution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any
liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly
or indirectly by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com in the Source Code/
Download section and on the book’s web site at http://jspro.org .
19073135.072.png
Contents at a Glance
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
PART 1 n n n Introducing Modern JavaScript
n CHAPTER 1
Modern JavaScript Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
PART 2 n n n Professional JavaScript Development
n CHAPTER 2
Object-Oriented JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
n CHAPTER 3
Creating Reusable Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
n CHAPTER 4
Tools for Debugging and Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
PART 3 n n n Unobtrusive JavaScript
n CHAPTER 5
The Document Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
n CHAPTER 6
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
n CHAPTER 7
JavaScript and CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
n CHAPTER 8
Improving Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
n CHAPTER 9
Building an Image Gallery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
PART 4 n n n Ajax
n CHAPTER 10 Introduction to Ajax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
n CHAPTER 11 Enhancing Blogs with Ajax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
n CHAPTER 12 Autocomplete Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
n CHAPTER 13 An Ajax Wiki . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
iii
19073135.073.png
PART 5 n n n The Future of JavaScript
n CHAPTER 14 Where Is JavaScript Going? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
PART 6 n n n Appendixes
n APPENDIX A DOM Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
n APPENDIX B Events Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
n APPENDIX C The Browsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
n INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
19073135.074.png
Zgłoś jeśli naruszono regulamin