Sams Teach Yourself Javascript in 24 Hours Acquisitions Editor Betsy Brown Copyright  2007 by Sams Publishing All Rights Reserved

Sams Teach Yourself Javascript in 24 Hours Acquisitions Editor Betsy Brown Copyright  2007 by Sams Publishing All Rights Reserved

Teach Yourself JavaScript in 24 Michael Moncur Hours 800 East 96th Street, Indianapolis, Indiana, 46240 USA Sams Teach Yourself JavaScript in 24 Hours Acquisitions Editor Betsy Brown Copyright 2007 by Sams Publishing All rights reserved. No part of this book shall be reproduced, stored in a Development Editor retrieval system, or transmitted by any means, electronic, mechanical, Songlin Qiu photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of Managing Editor the information contained herein. Although every precaution has been Patrick Kanouse taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for Senior Project Editor damages resulting from the use of the information contained herein. Matthew Purcell International Standard Book Number: 0-672-32879-8 Copy Editor Library of Congress Catalog Card Number: 2005909315 Jessica McCarty Printed in the United States of America Indexer First Printing: July 2006 Tim Wright 09080706 4321 Proofreader Trademarks Carla Lewis All terms mentioned in this book that are known to be trademarks or Technical Editor service marks have been appropriately capitalized. Sams Publishing Jim O’Donnell cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark Publishing Coordinator or service mark. Vanessa Evans Warning and Disclaimer Book Designer Every effort has been made to make this book as complete and as accu- Gary Adair rate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The author and the publisher shall have Page Layout neither liability nor responsibility to any person or entity with respect to TnT Design, Inc. any loss or damages arising from the information contained in this book. Bulk Sales Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact U.S. Corporate and Government Sales 1-800-382-3419 [email protected] For sales outside of the U.S., please contact International Sales [email protected] Contents at a Glance Introduction................................................................................1 Part I: Introducing the Concept of Web Scripting and the JavaScript Language HOUR 1 Understanding JavaScript..............................................................7 2 Creating Simple Scripts ...............................................................23 3 Getting Started with JavaScript Programming .................................37 4 Working with the Document Object Model (DOM)...........................49 Part II: Learning JavaScript Basics HOUR 5 Using Variables, Strings, and Arrays ..............................................63 6 Using Functions and Objects ........................................................85 7 Controlling Flow with Conditions and Loops.................................101 8 Using Built-in Functions and Libraries .........................................121 Part III: Learning More About the DOM HOUR 9 Responding to Events ................................................................139 10 Using Windows and Frames .......................................................157 11 Getting Data with Forms ...........................................................173 12 Working with Style Sheets ..........................................................191 13 Using the W3C DOM ................................................................207 14 Using Advanced DOM Features...................................................219 Part IV: Working with Advanced JavaScript Features HOUR 15 Unobtrusive Scripting ................................................................235 16 Debugging JavaScript Applications..............................................255 17 AJAX: Remote Scripting .............................................................273 18 Greasemonkey: Enhancing the Web with JavaScript .......................293 Part V: Building Multimedia Applications with JavaScript HOUR 19 Using Graphics and Animation ..................................................313 20 Working with Sound and Plug-ins ...............................................329 Part VI: Creating Complex Scripts HOUR 21 Building JavaScript Drop-down Menus .........................................345 22 Creating a JavaScript Game .......................................................359 23 Creating JavaScript Applications.................................................377 24 Your Future with JavaScript ........................................................393 Part VII: Appendixes A Other JavaScript Resources .........................................................409 B Tools for JavaScript Developers ...................................................411 C Glossary..................................................................................415 D JavaScript Quick Reference.........................................................419 E DOM Quick Reference ...............................................................427 Index .....................................................................................433 Table of Contents Part I: Introducing the Concept of Web Scripting and the JavaScript Language HOUR 1: Understanding JavaScript 7 Learning Web Scripting Basics ................................................................7 How JavaScript Fits into a Web Page ........................................................9 Browsers and JavaScript ........................................................................12 Specifying JavaScript Versions ................................................................15 JavaScript Beyond the Browser ..............................................................16 Exploring JavaScript’s Capabilities ..........................................................16 Alternatives to JavaScript ......................................................................17 HOUR 2: Creating Simple Scripts 23 Tools for Scripting ................................................................................23 Displaying Time with JavaScript ............................................................25 Beginning the Script ............................................................................26 Adding JavaScript Statements ................................................................26 Creating Output ..................................................................................27 Adding the Script to a Web Page ............................................................28 Testing the Script ................................................................................29 HOUR 3: Getting Started with JavaScript Programming 37 Basic Concepts ....................................................................................37 JavaScript Syntax Rules ........................................................................42 Using Comments ................................................................................43 Best Practices for JavaScript ..................................................................44 HOUR 4: Working with the Document Object Model (DOM) 49 Understanding the Document Object Model (DOM) ..................................49 Using Window Objects ..........................................................................51 Working with Web Documents ..............................................................52 Accessing Browser History ....................................................................55 Working with the Location Object ..........................................................55 vi Sams Teach Yourself JavaScript in 24 Hours Part II: Learning JavaScript Basics HOUR 5: Using Variables, Strings, and Arrays 63 Using Variables ..................................................................................63 Understanding Expressions and Operators ..............................................67 Data Types in JavaScript ......................................................................68 Converting Between Data Types ............................................................69 Using String Objects ............................................................................70 Working with Substrings ......................................................................74 Using Numeric Arrays ..........................................................................76 Using String Arrays ..............................................................................77 Sorting a Numeric Array ......................................................................79 HOUR 6: Using Functions and Objects 85 Using Functions ..................................................................................85 Introducing Objects ..............................................................................90 Using Objects to Simplify Scripting ........................................................91 Extending Built-in Objects ....................................................................94 HOUR 7: Controlling Flow with Conditions and Loops 101 The if Statement ................................................................................102 Using Shorthand Conditional Expressions ..............................................105 Testing

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    456 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us