您的位置:首页 > Web前端 > JavaScript

学习 JavaScript and Ajax for the Web (Sixth Edition)

2008-03-29 20:25 627 查看
By Tom Negrino, Dori Smith
Publisher: Peachpit Press
Pub Date: August 28, 2006
Print ISBN-10: 0-321-43032-8
Print ISBN-13: 978-0-321-43032-8
Pages: 512




Chapter 1. Getting Acquainted with JavaScript

What JavaScript Is
JavaScript Isn't Java
Where JavaScript Came From
What JavaScript Can Do


What JavaScript Can't Do

JavaScript不允许读取或者改写客户机上的文件。
JavaScript不允许改写服务器机器上的文件。
JavaScript不能关闭不是它打开的窗口。
JavaScript不能从别的服务器上打开的网页上读取信息。

What Is Ajax?
The Snap-Together Language
Handling Events
Values and Variables
Assignments and Comparisons


Writing JavaScript-Friendly HTML

要编写现代的,符合标准的XHTML,并且使用CSS来分离文档的表现和结构。网站应该包含三种类型的文本文件:
# XHTML: 包含页面的内容和结构
# CSS: 控制页面的外观和表现
# JavaScript: 控制页面的行为

XHTML包含了两个很重要的标签:<div>和<span>。它们被用于将内容分隔为具有语义的块结构。<div>是块层次的元素,在它和其他的元素之间有物理上的分段。而<span>是inline的元素。

class和id: class标识了可以使用多次的元素,而id标识了文档中唯一的元素。
class:
.movieTitel {font: bold 14px; color: white;}

<p>We're currently showing <span class="movieTitle"> The Aviator</span> and <span class="movieTitle"> The Outlaw</span>.</p>

id:
#theaterName {font: bold 28px; color: red;}
<h1 id="theaterName">The Raven Theater Presents:</h1>

What Tools to Use?

Chapter 2. Start Me Up!

<html> <head> <script language type src> <title> <body bgcolor> <h1> <h6 aligh> <a href id> ...

Where to Put Your Scripts
About Functions
Using External Scripts
Putting Comments in Scripts
Alerting the User
Confirming a User's Choice
Prompting the User
Redirecting the User with a Link
Using JavaScript to Enhance Links
Working with Referrer Pages


Chapter 3. Language Essentials

<table> <tr> <th> <td>

Around and Around with Loops

Passing a Value to a Function
----------------------------------------
function currentScore(hometeam, visitors)

Detecting Objects
--------------------
if (document.getElementById) { }

Working with Arrays
---------------------
var newCars = new Array("Toyota", "Honda", "Nissan");
var colPlace = new Array(0,1,2,3,4, 0,1,2,3,4,0,1,3,4,0,1,2,3,4,0,1, 2,3,4);
var newNum = (colPlace[thisSquare] * 15) + Math.floor(Math.random() * 15) + 1;

Working with Functions That Return Values
---------------------------------------------
var newNum = colBasis + getNewNum() + 1;

function getNewNum() {
return Math.floor(Math.random() * 15);
}

Updating Arrays
-----------------
var usedNums = new Array(76);
usedNums[newNum] = true;

Using Do/While Loops
Calling Scripts Multiple Ways
Using Multi-level Conditionals


Handling Errors
------------------
var ans = prompt("Enter a number","");
try {
if (!ans || isNaN(ans) || ans<0) {
throw new Error("Not a valid number");
}
alert("The square root of " + ans + " is " + Math.sqrt(ans));
}
catch (errMsg) {
alert(errMsg.message);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: