在好例子网,分享、交流、成长!
您当前所在位置:首页js 开发实例JavaScript基础 → JavaScript,A.Beginner's.Guide,Third.Edition

JavaScript,A.Beginner's.Guide,Third.Edition

JavaScript基础

下载此实例
  • 开发语言:js
  • 实例大小:6.29M
  • 下载次数:4
  • 浏览次数:35
  • 发布时间:2022-11-21
  • 实例类别:JavaScript基础
  • 发 布 人:王科
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: Javascript Javascrip script GUIDE java

实例介绍

【实例简介】JavaScript,A.Beginner's.Guide,Third.Edition

【实例截图】

from clipboard

【核心代码】

Contents
ACKNOWLEDGMENTS ........................................................... xix
INTRODUCTION .................................................................. xxi
1 Introduction to JavaScript ................................................ 1
What You Need to Know ............................................................ 2
Basic HTML and CSS Knowledge ............................................ 3
Basic Text Editor and Web Browser Knowledge ............................... 3
Which Version? ............................................................... 6
Remember, It’s Not Java ...................................................... 7
Similarities to Other Languages ............................................... 8
Beginning with JavaScript .......................................................... 8
Object Based ................................................................. 8
Client Side ................................................................... 8
Scripting Language ........................................................... 9
Putting It All Together .............................................................. 9
Online Resources ................................................................... 10
Try This 1-1: Use JavaScript to Write Text .......................................... 10
x JavaScript: A Beginner’s Guide
2 Placing JavaScript in an HTML File ..................................... 15
Using the HTML Script Tags ....................................................... 16
Identifying the Scripting Language ............................................ 16
Calling External Scripts ....................................................... 17
Using <noscript></noscript> Tags ............................................ 17
Creating Your First Script ........................................................... 19
Writing a “Hello World” Script ............................................... 19
Creating an HTML Document for the Script ................................... 20
Inserting the Script into the HTML Document ................................. 20
Try This 2-1: Insert a Script into an HTML Document ............................... 22
Using External JavaScript Files ..................................................... 23
Creating a JavaScript File ..................................................... 23
Creating the HTML Files ..................................................... 24
Viewing the Pages in Your Browser ........................................... 25
Try This 2-2: Call an External Script from an HTML Document ..................... 26
Using JavaScript Comments ........................................................ 27
Inserting Comments on One Line ............................................. 28
Adding Multiple-Line Comments ............................................. 28
3 Using Variables ........................................................... 33
Understanding Variables ............................................................ 34
Why Variables Are Useful .......................................................... 35
Variables as Placeholders for Unknown Values ................................ 35
Variables as Time-Savers ..................................................... 35
Variables as Code Clarifiers ................................................... 36
Defining Variables for Your Scripts ................................................. 36
Declaring Variables ........................................................... 36
Assigning Values to Variables ................................................. 36
Naming Variables ............................................................. 38
Understanding Variable Types ...................................................... 40
Number ...................................................................... 40
String ......................................................................... 41
Boolean ...................................................................... 46
Null .......................................................................... 46
Try This 3-1: Declare Variables ..................................................... 47
Using Variables in Scripts ........................................................... 48
Making a Call to a Variable ................................................... 49
Adding Variables to Text Strings .............................................. 49
Writing a Page of JavaScript ........................................................ 51
Creating the Framework ...................................................... 51
Defining the Variables ........................................................ 51
Adding the Commands ....................................................... 52
Modifying the Page ........................................................... 53
Try This 3-2: Create an HTML Page with JavaScript ................................ 55
 Contents xi
4 Using Functions ........................................................... 59
What a Function Is .................................................................. 60
Why Functions Are Useful .......................................................... 60
Structuring Functions ............................................................... 61
Declaring Functions .......................................................... 61
Defining the Code for Functions .............................................. 62
Naming Functions ............................................................ 63
Adding Parameters to Functions .............................................. 64
Adding Return Statements to Functions ....................................... 66
Calling Functions in Your Scripts ................................................... 67
Script Tags: Head Section or Body Section .................................... 68
Calling a Function from Another Function .................................... 70
Calling Functions with Parameters ............................................ 72
Calling Functions with Return Statements ..................................... 76
Other Ways to Define Functions .............................................. 76
Try This 4-1: Create an HTML Page with Functions ................................. 79
Putting It All Together .............................................................. 81
Try This 4-2: Write Your Own Functions ............................................ 83
5 JavaScript Operators ..................................................... 87
Understanding the Operator Types .................................................. 88
Understanding Mathematical Operators ............................................. 89
The Addition Operator ( ) .................................................... 90
The Subtraction Operator (–) .................................................. 92
The Multiplication Operator (*) ............................................... 92
The Division Operator (/) ..................................................... 93
The Modulus Operator (%) ................................................... 94
The Increment Operator ( ) ................................................. 94
The Decrement Operator (– –) ................................................ 95
The Unary Negation Operator (–) ............................................. 96
Understanding Assignment Operators ............................................... 97
The Assignment Operator (=) ................................................. 97
The Add-and-Assign Operator ( =) ........................................... 98
The Subtract-and-Assign Operator (–=) ....................................... 99
The Multiply-and-Assign Operator (*=) ....................................... 99
The Divide-and-Assign Operator (/=) ......................................... 99
The Modulus-and-Assign Operator (%=) ...................................... 99
Try This 5-1: Adjust a Variable Value ............................................... 100
Understanding Comparison Operators ............................................... 101
The Is-Equal-To Operator (==) ................................................ 102
The Is-Not-Equal-To Operator (!=) ............................................ 103
The Is-Greater-Than Operator (>) ............................................. 103
The Is-Less-Than Operator (<) ................................................ 104
xii JavaScript: A Beginner’s Guide
The Is-Greater-Than-or-Equal-To Operator (>=) .............................. 104
The Is-Less-Than-or-Equal-To Operator (<=) ................................. 105
The Strict Is-Equal-To Operator (===) ........................................ 105
The Strict Is-Not-Equal-To Operator (!==) .................................... 106
Understanding Logical Operators ................................................... 107
The AND Operator (&&) ..................................................... 107
The OR Operator (||) .......................................................... 107
The NOT Operator (!) ........................................................ 108
The Bitwise Operators ........................................................ 108
Special Operators ................................................................... 109
Understanding Order of Operations ................................................. 110
Try This 5-2: True or False? ........................................................ 111
6 Conditional Statements and Loops ....................................... 115
Defining Conditional Statements .................................................... 116
What Is a Conditional Statement? ............................................. 116
Why Conditional Statements Are Useful ...................................... 117
Using Conditional Statements ....................................................... 117
Using if/else Statement Blocks ................................................ 117
Using the switch Statement ................................................... 125
Using the Conditional Operator ............................................... 126
Try This 6-1: Construct an if/else Block ............................................. 129
Defining Loops ..................................................................... 130
What Is a Loop? .............................................................. 130
Why Loops Are Useful ....................................................... 130
Using Loops ........................................................................ 131
for ............................................................................ 131
while ......................................................................... 137
do while ...................................................................... 139
for in ......................................................................... 140
for each in .................................................................... 140
Using break and continue ..................................................... 141
Try This 6-2: Work with for Loops and while Loops ................................. 143
7 Event Handlers ........................................................... 147
What Is an Event Handler? .......................................................... 148
Why Event Handlers Are Useful .................................................... 148
Understanding Event Handler Locations and Uses ................................... 149
Using an Event Handler in an HTML Element ................................ 149
Using an Event Handler in the Script Code .................................... 151
Try This 7-1: Create a Button ....................................................... 153
Learning the Event Handlers ........................................................ 154
The Abort Event (onabort) .................................................... 155
The Blur Event (onblur) ...................................................... 155
 Contents xiii
The Change Event (onchange) ................................................ 156
The Click Event (onclick) ..................................................... 157
The Focus Event (onfocus) ................................................... 158
The Keydown Event (onkeydown) ............................................ 159
The Keypress Event (onkeypress) ............................................. 160
The Keyup Event (onkeyup) .................................................. 160
The Load Event (onload) ..................................................... 160
The Mousedown Event (onmousedown) ...................................... 161
The Mousemove Event (onmousemove) ...................................... 161
The Mouseover Event (onmouseover) ......................................... 162
The Mouseout Event (onmouseout) ........................................... 163
The Mouseup Event (onmouseup) ............................................. 164
The Reset Event (onreset) ..................................................... 164
The Submit Event (onsubmit) ................................................. 164
The Unload Event (onunload) ................................................. 164
Try This 7-2: Use Events to Send Out Alerts ........................................ 165
Creating Scripts Using Event Handlers .............................................. 167
The Text Box Message ........................................................ 167
The Button Link .............................................................. 169
Other Ways to Register Events ...................................................... 171
The addEventListener() Method .............................................. 172
The attachEvent() Method .................................................... 172
8 Objects .................................................................... 175
Defining Objects ................................................................... 176
What Is an Object? ........................................................... 176
Why Objects Are Useful ...................................................... 177
Creating Objects .................................................................... 177
Naming ....................................................................... 177
Object Structure .............................................................. 178
Adding Methods .............................................................. 186
Object Manipulation Statements .............................................. 190
Try This 8-1: Create a Computer Object ............................................. 193
Understanding Predefined JavaScript Objects ....................................... 194
The Navigator Object ......................................................... 194
The History Object ........................................................... 199
Try This 8-2: Practice with the Predefined Navigator Object ......................... 201
9 The Document Object ..................................................... 205
Defining the Document Object ...................................................... 206
Using the Document Object Model ................................................. 206
Using the Properties of the Document Object ....................................... 207
The Color Properties .......................................................... 210
The anchors Property (Array) ................................................. 210
xiv JavaScript: A Beginner’s Guide
The cookie Property .......................................................... 210
The dir Property .............................................................. 211
The domain Property ......................................................... 212
The formname Property ....................................................... 213
The forms Property (Array) ................................................... 215
The images Property (Array) .................................................. 215
The lastModified Property .................................................... 217
The layers Property (Array) ................................................... 217
The all Property .............................................................. 218
The links Property (Array) .................................................... 219
The referrer Property ......................................................... 219
The title Property ............................................................. 219
The URL Property ............................................................ 220
The URLUnencoded Property ................................................ 220
Using the Methods of the Document Object ......................................... 222
The getElementById() Method ................................................ 224
The getElementsByClassName() Method ..................................... 224
The getElementsByTagName() Method ....................................... 225
The open() and close() Methods ............................................... 225
The write() Method ........................................................... 227
The writeln() Method ......................................................... 227
Creation Methods ............................................................. 228
Try This 9-1: Add a DOM Node to the Document ................................... 233
Creating Dynamic Scripts ........................................................... 234
Styles in JavaScript ........................................................... 234
Coding a Dynamic Script ..................................................... 235
The innerHTML Property ..................................................... 236
Try This 9-2: Trying out Property Changes .......................................... 238
10 Window Object ........................................................... 241
An Introduction to the Window Object .............................................. 242
Using the Properties of the Window Object ......................................... 242
The closed Property .......................................................... 243
The defaultStatus Property .................................................... 244
The frames Property (Array) .................................................. 244
The innerHeight and innerWidth Properties ................................... 244
The length Property ........................................................... 246
The location Property ......................................................... 246
The name Property ........................................................... 246
The opener Property .......................................................... 247
The parent Property ........................................................... 248
The self Property ............................................................. 248
The status Property ........................................................... 248
The top Property .............................................................. 248
 Contents xv
Try This 10-1: Use the location and innerWidth Properties .......................... 248
Using the Methods of the Window Object ........................................... 249
The alert() Method ............................................................ 249
The confirm() Method ........................................................ 251
The find() Method ............................................................ 253
The home() Method .......................................................... 253
The print() Method ........................................................... 254
The prompt() Method ......................................................... 255
The open() Method ........................................................... 256
The close() Method ........................................................... 261
The moveBy() Method ........................................................ 262
The moveTo() Method ........................................................ 263
The resizeBy() Method ....................................................... 265
The resizeTo() Method ........................................................ 265
The scrollBy() Method ........................................................ 265
The scrollTo() Method ........................................................ 265
The setInterval() Method ..................................................... 265
The clearInterval() Method ................................................... 266
The setTimeout() Method ..................................................... 267
The clearTimeout() Method ................................................... 267
Try This 10-2: Use the setTimeout() and confirm() Methods ......................... 269
11 JavaScript Arrays ......................................................... 273
What Is an Array? .................................................................. 274
Why Arrays Are Useful ............................................................. 275
Defining and Accessing Arrays ..................................................... 275
Naming an Array ............................................................. 275
Defining an Array ............................................................ 276
Accessing an Array’s Elements ............................................... 276
Other Ways to Define Arrays .................................................. 277
Understanding the Properties and Methods of the Array Object ...................... 279
Properties .................................................................... 279
Methods ...................................................................... 282
Extended Array Methods ..................................................... 291
Using Arrays with Loops ........................................................... 292
Creating Array Elements ...................................................... 292
Moving Through Arrays ...................................................... 293
Try This 11-1: Use Loops with Arrays ............................................... 297
Using Associative Arrays ........................................................... 298
Defining Associative Arrays .................................................. 299
Accessing Associative Arrays ................................................. 299
Try This 11-2: Use Associative Arrays .............................................. 301
xvi JavaScript: A Beginner’s Guide
12 Math, Number, and Date Objects ......................................... 305
Using the Math Object .............................................................. 306
What Is the Math Object? ..................................................... 306
How the Math Object Is Useful ............................................... 306
Properties .................................................................... 306
Methods ...................................................................... 308
Try This 12-1: Display a Random Link on a Page ................................... 321
Understanding the Number Object .................................................. 322
Properties .................................................................... 322
Methods ...................................................................... 324
Using the Date Object .............................................................. 326
Properties .................................................................... 326
Methods ...................................................................... 327
Methods That Get Values ..................................................... 329
Methods That Set Values ...................................................... 332
Other Methods ................................................................ 333
How About Some Date Scripts? ............................................... 334
Try This 12-2: Create a JavaScript Clock ............................................ 338
13 Handling Strings .......................................................... 341
Introduction to the String Object .................................................... 342
The String Object ............................................................. 342
The String Literal ............................................................. 343
What’s the Difference? ....................................................... 343
Using the Properties of the String Object ............................................ 344
The constructor Property ...................................................... 344
The length Property ........................................................... 344
The prototype Property ....................................................... 345
Using the Methods of the String Object ............................................. 345
Methods That Add HTML Tags ............................................... 345
The Other Methods ........................................................... 351
Try This 13-1: Use charAt() to Find a First Letter ................................... 359
Putting Methods Together ........................................................... 360
Try This 13-2: Use indexOf() to Test an Address .................................... 362
Using Regular Expressions ......................................................... 363
Creating Regular Expressions ................................................. 363
Testing Strings Against Regular Expressions .................................. 364
Adding Flags ................................................................. 365
Creating Powerful Patterns .................................................... 366
Grouping Expressions ........................................................ 369
The replace(), match(), and search() Methods ................................. 370
More Information ............................................................. 372
 Contents xvii
14 JavaScript and Forms ..................................................... 375
Accessing Forms ................................................................... 376
Using the forms Array ........................................................ 376
Using Form Names ........................................................... 380
Using an ID .................................................................. 381
Using the Properties and Methods of the Form Object ............................... 382
Properties .................................................................... 382
Methods ...................................................................... 392
Ensuring the Accessibility of Forms ................................................. 392
Using Proper Element and Label Order ....................................... 393
Using <label></label> Tags ................................................... 393
Using <fieldset></fieldset> Tags .............................................. 393
Not Assuming Client-Side Scripting .......................................... 394
Validation .......................................................................... 395
onsubmit and the return Statement ............................................ 395
Techniques ................................................................... 396
Try This 14-1: Request a Number ................................................... 398
Using Forms for Navigation ........................................................ 399
Clicking a Button ............................................................. 399
Try This 14-2: Build a Select Box Navigation Script ................................ 403
15 JavaScript and Frames ................................................... 407
An Introduction to Frames .......................................................... 408
Purpose of Frames ............................................................ 408
The Code Behind the Frames ................................................. 409
Frame Options ................................................................ 411
Accessing Frames .................................................................. 414
The frames Array ............................................................. 414
Using a Frame Name ......................................................... 417
Changing Frames ................................................................... 418
Change a Single Frame ....................................................... 418
Change Multiple Frames ...................................................... 419
Try This 15-1: Change Frames ...................................................... 422
Step by Step .................................................................. 422
Frame Navigation ................................................................... 423
Using the Select Box with Frames ............................................ 423
Breaking Out of Frames ...................................................... 424
Sending Viewers to Frames ................................................... 426
Using Variables Across Frames ..................................................... 428
Try This 15-2: Use Variables ........................................................ 432
xviii JavaScript: A Beginner’s Guide
16 An Introduction to Advanced Techniques ................................ 435
Debugging Scripts .................................................................. 436
Types of Errors ............................................................... 436
JavaScript and Accessibility ........................................................ 442
Separate Content from Presentation ........................................... 442
Enhancing Content ........................................................... 444
Try This 16-1: Make This Code Accessible .......................................... 445
Using Cookies ...................................................................... 446
Setting a Cookie .............................................................. 446
Reading a Cookie ............................................................. 449
Try This 16-2: Remember a Name .................................................. 451
Working with Images ............................................................... 452
Preloading .................................................................... 452
Rollovers ..................................................................... 454
JavaScript Security ................................................................. 460
Security and Signed Scripts ................................................... 460
Page Protection ............................................................... 460
AJAX .............................................................................. 462
JavaScript Libraries ................................................................. 463
A Answers to Self Tests ...................................................... 467
Chapter 1: Introduction to JavaScript ................................................ 468
Chapter 2: Placing JavaScript in an HTML File ..................................... 468
Chapter 3: Using Variables .......................................................... 469
Chapter 4: Using Functions ......................................................... 469
Chapter 5: JavaScript Operators ..................................................... 470
Chapter 6: Conditional Statements and Loops ....................................... 471
Chapter 7: Event Handlers .......................................................... 471
Chapter 8: Objects .................................................................. 472
Chapter 9: The Document Object ................................................... 473
Chapter 10: Window Object ......................................................... 473
Chapter 11: JavaScript Arrays ....................................................... 474
Chapter 12: Math, Number, and Date Objects ....................................... 475
Chapter 13: Handling Strings ....................................................... 475
Chapter 14: JavaScript and Forms ................................................... 476
Chapter 15: JavaScript and Frames .................................................. 477
Chapter 16: An Introduction to Advanced Techniques ............................... 477
Index ...................................................................... 479

实例下载地址

JavaScript,A.Beginner's.Guide,Third.Edition

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警