hungry minds javascript weekend crash course

427 427 0
hungry minds javascript weekend crash course

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

JAVASCRIPT STEVEN W. DISBROW JavaScript columnist, Java Report magazine CD-ROM with all sample code plus assessment tools 30 Sessions That Will Have You Scripting in Only 15 Hours JAVASCRIPT 15 15 WEEKEND CRASH COURSE WEEKEND CRASH COURSE ™ HOURS ® JavaScript ® Weekend Crash CourseJavaScript ® Weekend Crash Course ™ Steven W. Disbrow Hungry Minds, Inc. New York, NY • Cleveland, OH • Indianapolis, IN JavaScript® Weekend Crash Course™ Published by Hungry Minds, Inc. 909 Third Avenue New York, NY 10022 www.hungryminds.com Copyright © 2001 Hungry Minds, Inc. All rights reserved. No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (elec- tronic, photocopying, recording, or otherwise) with- out the prior written permission of the publisher. Library of Congress Control Number: 2001016760 ISBN: 0-7645-4804-2 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 1B/SV/QU/QR/IN Distributed in the United States by Hungry Minds, Inc. Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia and New Zealand; by TransQuest Publishers Pte Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria, and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc. for Micronesia; by Chips Computadoras S.A. de C.V. for Mexico; by Editorial Norma de Panama S.A. for Panama; by American Bookshops for Finland. For general information on Hungry Minds’ products and services please contact our Customer Care department within the U.S. at 800-762-2974, out- side the U.S. at 317-572-3993 or fax 317-572-4002. For sales inquiries and reseller information, includ- ing discounts, premium and bulk quantity sales, and foreign-language translations, please contact our Customer Care department at 800-434-3422, fax 317-572-4002 or write to Hungry Minds, Inc., Attn: Customer Care Department, 10475 Crosspoint Boulevard, Indianapolis, IN 46256. For information on licensing foreign or domestic rights, please contact our Sub-Rights Customer Care department at 212-884-5000. For information on using Hungry Minds’ products and services in the classroom or for ordering exam- ination copies, please contact our Educational Sales department at 800-434-2086 or fax 317-572-4005. For press review copies, author interviews, or other publicity information, please contact our Public Relations department at 317-572-3168 or fax 317-572-4168. For authorization to photocopy items for corporate, personal, or educational use, please contact Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, or fax 978-750-4470. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO REPRESENTA- TIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ACCURACY AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT GUARAN- TEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES. Netscape Communications Corporation has not authorized, sponsored, endorsed, or approved this publica- tion and is not responsible for its content. Netscape and the Netscape Communications Corporate Logos are trademarks and trade names of Netscape Communications Corporation. Trademarks: Weekend Crash Course is a trademark or registered trademark of Hungry Minds, Inc. JavaScript is a registered trademark or trademark of Sun Microsystems, Inc. All other trademarks are the property of their respective owners. Hungry Minds, Inc., is not associated with any product or vendor mentioned in this book. is a trademark of Hungry Minds, Inc. About the Author Steven W. Disbrow (a.k.a. “Diz”) is a freelance writer, technical instructor, and programmer. He was the publisher of GS+ Magazine from 1989 to 1995. Since then, he’s been writing articles for various technical publications and is the current “JavaScripting” columnist for Java Report magazine. He also creates and delivers courseware for most Web-based technologies including JavaScript, HTML, and XML. This is his first book. Acquisitions Editor Debra Williams Cauley Project Editors Barbra Guerra Neil Romanosky Technical Editor Galen Mayfield Copy Editor Maarten Reilingh Project Coordinator Dale White Graphics and Production Specialists Joe Bucki Sean Decker Quality Control Technicians Laura Albert Andy Hollandbeck Permissions Editor Laura Moss Media Development Specialist Travis Silvers Media Development Coordinator Marisa Pearman Proofreading and Indexing York Production Services, Inc. Credits This book is dedicated to everyone who supported GS+ Magazine, my parents, and Robin and Maia. T his book is for anyone who needs to learn how to create a JavaScript-based Web site. If you have no programming experience, you’ll find a complete introduction to the JavaScript language along with examples of how to carry out common Web-programming tasks. If you already know about “JavaScript the language,” you’ll find a ton of tips and techniques that you can use to enhance your existing Web sites. Who Should Read this Book If you need to put together a Web site that does something more than just sit there, this book is for you. Over the course of one weekend, you’ll learn about the JavaScript language and how it fits into the scheme of Web page creation. Along the way, you’ll learn about lots of other Web-based technologies and how JavaScript can work with them to create interactive and interesting Web sites. It’s important to note that this is not a JavaScript reference book! If you are looking for table after table of JavaScript language minutiae, you won’t find it here. Instead, you’ll find examples of how JavaScript can be used to solve real Web-programming challenges. What’s in this Book This book is divided into 30 sessions, each addressing one aspect of the JavaScript language or some technique for which JavaScript can be used. Each of these ses- sions should take you about 30 minutes to get through, although you can expect Preface to spend more time with each session if you examine the source code on the accompanying CD-ROM. Because the goal of this book is to teach you the basics of JavaScript in a weekend, it’s been broken into six parts: ¼ Part I contains four lessons (which should take about two hours to com- plete) that will teach you the basics of the JavaScript language and how JavaScript fits into a Web page. ¼ Part II is six sessions long (and should take about three hours to com- plete). It will introduce you to some of JavaScript’s built-in objects, the Browser Object Model, and the concept of browser events. ¼ Part III is also six sessions in length. The focus of this part of the book is on how JavaScript can be used to dynamically create HTML and manipulate the various controls that are found in an HTML form. ¼ Part IV is just four sessions long, but that’s just enough time to give you an understanding of how you can create your own objects with JavaScript and use them to enhance your Web pages. The last session in this part also tells you how you can dynamically build and execute JavaScript state- ments after your Web page has been loaded. ¼ Part V is six sessions long. The sessions in this part focus on identifying different browsers, using Dynamic HTML and Cascading Style Sheets, and working with windows and frames. ¼ Part VI is four sessions long and focuses on how JavaScript can be used to communicate with other processes. These include server-side CGI processes, browser plug-ins, and Java applets. At the end of each session, you’ll find a short summary and a set of questions, both designed to remind you of what you’ve learned in that session. At the end of each part, you’ll find twenty questions that will test how much you actually remember from the previous sessions. Some of these will be simple short-answer questions, but many are actual programming puzzles. You are encouraged to try and solve these on your own, but, if you need the answers right away, you’ll find them on your CD-ROM. Once you’ve finished the entire book, you’ll probably want to try the self-assessment test on the CD-ROM. This is a simple multiple-choice test that will give you a good idea of how much you’ve actually learned. In keeping with the title Weekend Crash Course, you’ll find that this book is about learning how to get things done with JavaScript. Because of that, this book is a bit different from most of the other JavaScript books out there. Whereas most books start off by telling you how fragmented the JavaScript “standard” is (each version of each browser has its own flavor of JavaScript) and then spend a tremen- dous amount of time teaching you how to work around all the differences, you’ll Prefacex be learning techniques that should work in all of the various browsers. Of course, you will learn how to work around browser differences, but you’ll find that it isn’t that hard or even all that necessary when using the latest browsers. The text itself is adorned with icons designed to catch your attention. The “minutes to go” icons mark your progress in the session. The Tip icon offers information that can save you time and effort. The Note icons highlight incidental or technical information that clarifies and expands the discussion. The CD-ROM icon refers to material furnished on the book’s CD. Use it to find electronic versions of programs and software elements mentioned in the text. CD-ROM Note Tip Preface xi [...]... Fortunately, like this book, JavaScript is one of the rare exceptions that probably won’t leave you feeling let down! Among other things, JavaScript can: 8 Friday Evening What JavaScript Can’t Do Of course, JavaScript isn’t perfect While JavaScript is very powerful, it’s also had some pretty severe restrictions placed upon it (Note that these restrictions are mostly found in the JavaScript that runs inside... the output of JavaScript with HTML tags Everything else that we discuss this weekend is built on these concepts, so be sure you’ve got a good handle on them before proceeding! QUIZ YOURSELF 1 Is JavaScript just a “slimmed-down” version of Java? (See “What JavaScript Can’t Do.”) 2 What are some of the things JavaScript can do? (See “So, What Can JavaScript Do?”) 3 What are some things JavaScript can’t... using the terms “program” and “script” to refer to blocks of JavaScript code While JavaScript is technically “just a scripting language,” it has all the computational power of a “real” programming language Besides, saying JavaScript script” sounds silly when compared to JavaScript program.” Session 1—Getting to Know JavaScript 7 So, What Can JavaScript Do? ¼ Generate custom Web pages and dynamically... .2 Part I—Friday Evening 4 Session 1–Getting to Know JavaScript 5 So, What Can JavaScript Do? 7 What JavaScript Can’t Do 8 How JavaScript Fits into a Web Page 8 Creating Your First JavaScript Program .11 Session 2–Statements and Operators 13 Assignment Statements 14 JavaScript Variables 14 Data types 15 Variable... Getting to Know JavaScript Session 2 Statements and Operators Session 3 Flow of Control Statements Session 4 How to Write JavaScript Functions PART I Friday Evening Session 1 Getting to Know JavaScript Session 2 Statements and Operators Session 3 Flow of Control Statements Session 4 How to Write JavaScript Functions SESSION 1 Getting to Know JavaScript Session Checklist Learning a bit of JavaScript s... controlled by the Web browser itself.) ¼ JavaScript can’t perform operations over the network (An exception to this rule is that JavaScript can force the Web browser to open a different Web page, which can be anywhere on the Web.) ¼ JavaScript can’t create stand-alone software Remember, JavaScript began life as a way to add interactivity to otherwise static Web pages So, JavaScript always has been (and probably... that most of the entries in this list involve Web pages However, JavaScript isn’t just restricted to Web browsers Netscape has a serverside version of JavaScript (called LiveWire or simply Server-Side JavaScript) , and Microsoft has included server-side JScript support in their Web server as well Both of these allow you to write server-side JavaScript programs that can perform all kinds of cool and useful... write JavaScript programs to automate tasks in Windows 95 and later In this book, however, we’ll be concentrating on JavaScript as it is used inside your favorite Web browser The main reason for this is that once you learn JavaScript for the Web, you can easily take that knowledge and apply it to any of these other environments So, in order to complete the exercises in this book, you must use a JavaScriptcapable... 15–Validating Form Data 175 Session 16–Cooking up Cookies with JavaScript 187 Part IV—Saturday Evening 204 Session 17–Understanding JavaScript Objects 205 Session 18–Creating and Using Methods .217 Session 19–Enhancing HTML with JavaScript Objects 227 Session 20–Dynamically Creating and Executing JavaScript .237 Contents xv SUNDAY 250 Part V—Sunday Morning... change the name of LiveScript to JavaScript This was an excellent move on Netscape’s part The name change got people to notice and try JavaScript, and the fact that it was actually a powerful language that could do amazing things got them to create Web pages that relied on it So it wasn’t long before JavaScript- enhanced Web pages began popping up all over the Web Eventually, JavaScript found its way into . Hours JAVASCRIPT 15 15 WEEKEND CRASH COURSE WEEKEND CRASH COURSE ™ HOURS ® JavaScript ® Weekend Crash Course ™ JavaScript ® Weekend Crash Course ™ Steven W. Disbrow Hungry Minds, Inc. New York,. OH • Indianapolis, IN JavaScript Weekend Crash Course Published by Hungry Minds, Inc. 909 Third Avenue New York, NY 10022 www.hungryminds.com Copyright © 2001 Hungry Minds, Inc. All rights reserved names of Netscape Communications Corporation. Trademarks: Weekend Crash Course is a trademark or registered trademark of Hungry Minds, Inc. JavaScript is a registered trademark or trademark of Sun

Ngày đăng: 28/04/2014, 16:50

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan