microsoft press javascript 2nd ed

478 256 0
microsoft press javascript 2nd ed

Đ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

Microsoft JavaScript SECON D EDITION Steve Suehring Published with the authorization of Microsoft Corporation by: O'Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, California 95472 Copyright © 2010 Steve Suehring Complying with all applicable copyright laws is the responsibility of the user. All rights reserved. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without express written permission of O'Reilly Media, Inc. Printed and bound in the United States of America. 123456789 M 543210 Microsoft Press titles may be purchased for educational, business or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or cotporate(a)orei lly.com. Visit our website at microsoftpress.oreilly.com. Send comments to mspinput(cbmicrosoft.com. Mcrosoft, Microsoft Press, ActiveX, Excel, FrontPage, Internet Explorer, PowerPoint, SharePoint, Webdings, Windows, and Windows 7 are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, prod- uct, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. This book expresses the author's views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the author, O'Reilly Media, Inc., Microsoft Corporation, nor their respective resellers or distributors, will be held liable for any damages caused or alleged to be caused either directly or indirectly by such information. Acquisitions and Development Editor: Russell Jones Production Editor: Holly Bauer Production Services: Online Training Solutions, Inc. Technical Reviewer: Michael Bazarewsky Indexing: Potomac Indexing, LLC Cover: Karen Montgomery Illustrator: Robert Romano Contents at a Glance Part I JavaWhat? The Where, Why, and How of JavaScript 1 JavaScript Is More Than You Might Think 3 2 Developing in JavaScript 19 3 JavaScript Syntax and Statements 49 4 Working with Variables and Data Types 61 5 Using Operators and Expressions 99 Part ii Applying JavaScript 6 Controlling Flow with Conditionals and Loops 119 7 Working with Functions 147 8 Objects in JavaScript 163 9 The Browser Object Model 181 Part ill Integrating JavaScript into Design 10 The Document Object Model 203 11 JavaScript Events and the Browser 223 12 Creating and Consuming Cookies 239 13 Working with Images in JavaScript 253 14 Using JavaScript with Web Forms 275 15 JavaScript and CSS 297 16 JavaScript Error Handling 313 Part iv AJAX and Server-Side Integration 17 JavaScript and XML 331 vi Contents at a Glance Part v jQuery 21 An Introduction to JavaScript Libraries and Frameworks 383 22 An Introduction to jQuery 387 23 jQuery Effects and Plug-Ins 415 Table of Contents Acknowledgements xvii Introducing JavaScript Step by Step, Second Edition xix Getting Help xxii Part I JavaWhat? The Where, Why, and How of JavaScript 1 JavaScript Is More Than You Might Think 3 A Brief History of JavaScript 3 Enter Internet Explorer 3.0 4 And Then Came ECMAScript 4 So Many Standards 5 The DOM 5 What's in a JavaScript Program? 6 JavaScript Placement on Your Webpage 7 What JavaScript Can Do 10 What JavaScript Can't Do 10 JavaScript Can't Be Forced on a Client 10 JavaScript Can't Guarantee Data Security 11 JavaScript Can't Cross Domains 11 JavaScript Doesn't Do Servers 12 Tips for Using JavaScript 12 Where JavaScript Fits 14 Which Browsers Should the Site Support? 15 What's New in ECMAScript Version 5? 16 New Array Methods 16 New Controls on Object Properties 16 New JSON Object 16 Changes to the Date Object 17 viii Table of Contents A New Strict Mode 17 Browser Support 17 Exercises 17 2 Developing in JavaScript 19 JavaScript Development Options 19 Configuring Your Environment 20 Writing JavaScript with Visual Studio 2010 20 Your First Web (and JavaScript) Project with Visual Studio 2010 24 Using External JavaScript Files with Visual Studio 2010 28 Writing JavaScript with Eclipse 33 Your First Web (and JavaScript) Project with Eclipse 33 Using External JavaScript Files with Eclipse 38 Writing JavaScript Without an IDE 41 Your First Web (and JavaScript) Project with Notepad 41 Using External JavaScript Files Without an IDE 44 Debugging JavaScript 46 Exercises 47 3 JavaScript Syntax and Statements 49 A Bit of Housekeeping 49 Case Sensitivity 49 White Space 50 Comments 51 Semicolons 51 Line Breaks 53 Placing JavaScript Correctly 53 JavaScript Statements 54 What's in a Statement? 54 The Two Types of JavaScript Statements 55 Reserved Words in JavaScript 55 A Quick Look at Functions 56 JavaScript's New Strict Mode 59 Table of Contents xiii 4 Working with Variables and Data Types 61 Data Types in JavaScript 61 Working with Numbers 62 Working with Strings 66 Booleans 71 Null 71 Undefined 71 Objects 72 Arrays 73 Defining and Using Variables 73 Declaring Variables 74 Variable Types 74 Variable Scope 75 The Date Object 82 Using the Reg Exp Object 91 The Syntax of Regular Expressions 92 References and Garbage Collection 96 Learning About Type Conversions 97 Number Conversions 97 String Conversions 98 Boolean Conversions 98 Exercises 98 5 Using Operators and Expressions 99 Meet the Operators 99 Additive Operators 99 Multiplicative Operators 100 Bitwise Operators 101 Equality Operators 102 Relational Operators 104 The in Operator 105 The instanceof Operator 105 viii Table of Contents Using the delete Operator 108 Returning Variable Types with the typeof Operator Ill The void Operator 112 Assignment Operators 113 The Comma Operator 114 Exercises 115 Part ii Applying JavaScript 6 Controlling Flow with Conditionals and Loops 119 If (and How) 119 Syntax for //Statements 119 The prompt() Function in Internet Explorer 121 Compound Conditions 124 Using else if and else Statements 126 Working with Ternary Conditionals 131 Testing with switch 132 Looping with while 134 The while Statement 134 The do while Statement 135 Using for Loops 137 The for Loop 137 The for in Loop 140 The for each in Loop 141 Validating Forms with Conditionals 143 Exercises 145 7 Working with Functions 147 What's in a Function? 147 Function Arguments 148 Variable Scoping Revisited 150 Return Values 151 More on Calling Functions 152 Table of Contents xiii 8 Objects in JavaScript 163 Object-Oriented Development 163 Objects 163 Properties 164 Methods 164 Classes 164 Creating Objects 167 Adding Properties to Objects 168 Adding Methods to Objects 171 Finding Out More About Arrays 171 The length Property 172 Array Methods 172 Taking Advantage of Built-in Objects 178 The Global Object 178 Exercises 180 9 The Browser Object Model 181 Introducing the Browser 181 The Browser Hierarchy 181 Events 182 A Sense of Self. 183 Getting Information About the Screen 185 Using the navigator Object 187 The location Object 191 The history Object 198 Exercises 199 Part ill Integrating JavaScript into Design 10 The Document Object Model 203 The Document Object Model Defined 203 DOM Level 0: The Legacy DOM 204 DOM Levels 1 and 2 204 viii Table of Contents HTML Collections 212 Working with Siblings 212 Working with Attributes 213 Viewing Attributes 213 Setting Attributes 216 Creating Elements 217 Adding Text 217 Adding an Element and Setting an ID 219 Deleting Elements 219 Exercises 221 11 JavaScript Events and the Browser 223 Understanding Window Events 223 The Event Models 223 A Generic Event Handler 227 Detecting Visitor Information 228 A Brief Look at the userAgent Property 229 Feature Testing 230 Keeping JavaScript Away from Older Browsers 231 Other navigator Properties and Methods 232 Opening, Closing, and Resizing Windows 233 Window Opening Best Practices 234 Opening Tabs: No JavaScript Necessary? 235 Resizing and Moving Windows 236 Timers 236 Exercises 238 12 Creating and Consuming Cookies 239 Understanding Cookies 239 Creating Cookies with JavaScript 240 Looking at a Simple Cookie 241 Setting a Cookie's Expiration Date 241 Setting the Cookie Path 245 [...]... but thank you, too Introducing JavaScript Step by Step, Second Edition Much has changed since the first edition of JavaScript Step by Step was written in 2007 The underlying JavaScript specification received a major update; Microsoft released Windows Internet Explorer 8—and now 9 (which is about to be released as I write this); JavaScript development frameworks have matured and are now ubiquitous; and... book examines JavaScript and helps you get started developing JavaScript applications You don't need any specific tools for JavaScript development, so you see how to create JavaScript files in Microsoft Visual Studio, in Eclipse, and even in Notepad (or any text editor) Next, the book examines JavaScript' s core language and functions, followed by an exploration of the relationship between JavaScript and... Eclipse to create and deploy a JavaScript application • Use Notepad (or another editor) to create a JavaScript application • Understand options for debugging JavaScript JavaScript Development Options Because JavaScript isn't a compiled language, you don't need any special tools or development environments to write and deploy JavaScript applications Likewise, you don't need special server software to... With the release of Microsoft Internet Explorer 3.0 in 1996, Microsoft included support for core JavaScript, known in Internet Explorer as JScript, as well as support for another scripting language called Microsoft Visual Basic, Scripting Edition, or VBScript Although JavaScript and JScript were similar, their implementations weren't exactly the same Therefore, methods were developed to detect which... Where, Why, and How of JavaScript What JavaScript Can Do JavaScript is largely a complementary language, meaning that it's uncommon for an entire application to be written solely in JavaScript without the aid of other languages like HTML and without presentation in a web browser Some Adobe products support JavaScript, but JavaScript is primarily used for web-related programming JavaScript is also the... about what JavaScript can do—the focus of this book—you need to understand what JavaScript can't do, but note that neither discussion is comprehensive What JavaScript Can't Do Many of the operations JavaScript can't perform are the result of JavaScript' s usage being somewhat limited to a web browser environment This section examines some of the tasks JavaScript can't perform and some that JavaScript. .. you need either to write code that takes into them into account, or use a JavaScript library such as jQuery This book covers various JavaScript libraries in Chapter 21, "An Introduction to JavaScript Libraries and Frameworks." Exercises 1 True or False: JavaScript is defined by a standards body and is supported on all web browsers 2 True or False: When a visitor whose machine has JavaScript disabled comes... chapter, you'll be able to: • Understand the history of JavaScript • Recognize the parts of a JavaScript program • Use the javascript pseudo-protocol • Understand where JavaScript fits within a webpage • Understand what JavaScript can and cannot do • Understand some of the changes in the latest standard related to JavaScript A Brief History of JavaScript JavaScript isn't Java There! With that clarification... the online Knowledge Base, send your comments or questions to Microsoft Learning Technical Support at: Part I JavaWhat? The Where, Why, and How of JavaScript Chapter 1: JavaScript Is More Than You Might Think Chapter 2: Developing in JavaScript Chapter 3: JavaScript Syntax and Statements Chapter 4: Working with Variables and Data Types Chapter 5: Using Operators and Expressions Chapter 1 JavaScript Is... http://www.w3.org/2003/02/06-dom-support.html What's in a JavaScript Program? A JavaScript program consists of statements formed from tokens, operators, and identifiers placed together in an order that is meaningful to a JavaScript interpreter, which is contained in most web browsers That sentence is a mouthful, but these statements are really not all that complicated to anyone who has programmed in just about any other language . without express written permission of O'Reilly Media, Inc. Printed and bound in the United States of America. 123456789 M 543210 Microsoft Press titles may be purchased for educational,. is intended or should be inferred. This book expresses the author's views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties Microsoft JavaScript SECON D EDITION Steve Suehring Published with the authorization of Microsoft Corporation by: O'Reilly Media, Inc. 1005 Gravenstein

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

Từ khóa liên quan

Mục lục

  • Team rebOOk

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

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

Tài liệu liên quan