📄 tutorial4_page3.htm
字号:
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb_2312-80">
<meta NAME="GENERATOR" CONTENT="Microsoft FrontPage 3.0">
<title>Webmonkey: javascript: Thau's JavaScript Tutorial: Day 1</title>
<meta NAME="keywords"
CONTENT="javascript, hotwired, webmonkey, javascript, javascript tutorial, thau, dave thau, developer resource, developer, development, web
development, design, code, geek, warez, free, new, latest, news, tools,
info, tutorials, how-to, builder, web builder, pag">
<meta NAME="description"
CONTENT="Thau's JavaScript Tutorial: Day 1: Not only does Thau give the JavaScript skinny, but he'll have you writing your first script by the end of the day.">
<meta NAME="Template" CONTENT="E:\LIZEJUN\OFFICE\html.dot">
</head>
<body TEXT="#000000" LINK="#0000ff" VLINK="#800080" BGCOLOR="#ffffff">
<table CELLSPACING="0" BORDER="0" CELLPADDING="3" WIDTH="540">
<tr>
<td WIDTH="68%" VALIGN="MIDDLE"><font FACE="宋体" LANG="ZH-CN" SIZE="4" COLOR="#ff0000"></font><font
FACE="System,黑体" LANG="ZH-CN" SIZE="5" COLOR="#ff0000"><b>第3页:循环密码</b></font><font
FACE="System,黑体" LANG="ZH-CN"><br>
<!-- BYLINE --> </font><font FACE="System,黑体" LANG="ZH-CN" SIZE="2">作者:</font><a
HREF="mailto:thau@wired.com"><font FACE="宋体" LANG="ZH-CN" SIZE="2">Thau!</font></a><font
FACE="宋体" LANG="ZH-CN"> <!-- SEE ALSO LINKS --></font></td>
</tr>
<tr>
<td WIDTH="68%" VALIGN="TOP" BGCOLOR="#ffffff"><font FACE="System,黑体" LANG="ZH-CN"
SIZE="2"><p ALIGN="JUSTIFY">那就是密码!</p>
<p ALIGN="JUSTIFY">让我们逐行地来研究这个例子,如果你想看整个答案,可以查看源码。</p>
<p ALIGN="JUSTIFY">在这个典型的</font><font FACE="宋体" LANG="ZH-CN">Java script </font><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2">序言之后,我们从双变量申报开始:</p>
<blockquote ALIGN="JUSTIFY">
<p><br>
<br>
</font><font FACE="Verdana, arial" SIZE="2">var password="pass the wrench";<br>
<br>
var answer;<br>
</font></p>
</blockquote>
<font FACE="System,黑体" LANG="ZH-CN" SIZE="2"><p ALIGN="JUSTIFY">这里我们定义该密码作为一个字符串,我们申报一个称为</font><font
FACE="宋体" LANG="ZH-CN">answer </font><font FACE="System,黑体" LANG="ZH-CN">的变量。你将理解为什么我们不得不立即申报一个</font><font
FACE="宋体" LANG="ZH-CN">answer</font><font FACE="System,黑体" LANG="ZH-CN" SIZE="2">。下面几行是非常重要的:</p>
<blockquote ALIGN="JUSTIFY">
<p><br>
<br>
</font><font FACE="Verdana, arial" SIZE="2">while (answer != password) <br>
<br>
{<br>
<br>
answer = prompt("What's the woyd?","");<br>
<br>
}<br>
</font></p>
</blockquote>
<font FACE="System,黑体" LANG="ZH-CN" SIZE="2"><p ALIGN="JUSTIFY">这是一个</font><font
FACE="宋体" LANG="ZH-CN">while</font><font FACE="System,黑体" LANG="ZH-CN">循环。</font><font
FACE="宋体" LANG="ZH-CN">while </font><font FACE="System,黑体" LANG="ZH-CN" SIZE="2">循环的一般格式为:</p>
<blockquote ALIGN="JUSTIFY">
<p><br>
<br>
</font><font FACE="Verdana, arial" SIZE="2">while (some test is true)<br>
<br>
{<br>
<br>
do the stuff inside the curly braces<br>
<br>
}<br>
</font></p>
</blockquote>
<font FACE="System,黑体" LANG="ZH-CN"><p ALIGN="JUSTIFY">上述几行表明:“当</font><font
FACE="宋体" LANG="ZH-CN">answer</font><font FACE="System,黑体" LANG="ZH-CN">不等价于</font><font
FACE="宋体" LANG="ZH-CN">Password</font><font FACE="System,黑体" LANG="ZH-CN">时,执行提示命令。”这一循环将持续地执行波形括号内的语句直至测试失败。在使用者输入的单词与密码一致</font><font
FACE="宋体" LANG="ZH-CN">(</font><font FACE="System,黑体" LANG="ZH-CN">即</font><font
FACE="宋体" LANG="ZH-CN">Pass the wrench)</font><font FACE="System,黑体" LANG="ZH-CN"
SIZE="2">的情况下,测试必将失败。</p>
</font><font FACE="System,黑体" LANG="ZH-CN"><p ALIGN="JUSTIFY">由于在对一个未申报的变量执行一个如</font><font
FACE="宋体" LANG="ZH-CN">(answer!=password)</font><font FACE="System,黑体"
LANG="ZH-CN">的测试时,在某些浏览器上会产生错误,所以我们必须申报</font><font
FACE="宋体" LANG="ZH-CN">answer</font><font FACE="System,黑体" LANG="ZH-CN">。由于在</font><font
FACE="宋体" LANG="ZH-CN">while</font><font FACE="System,黑体" LANG="ZH-CN">循环中将通过提示方案对</font><font
FACE="宋体" LANG="ZH-CN">answer</font><font FACE="System,黑体" LANG="ZH-CN">赋值,在我们第一次进行循环中,</font><font
FACE="宋体" LANG="ZH-CN">answer</font><font FACE="System,黑体" LANG="ZH-CN" SIZE="2">将没有数值。提前定义它并设定其处始值为“”。</p>
</font><font FACE="System,黑体" LANG="ZH-CN"><p ALIGN="JUSTIFY">由于不定义循环经常地使用,循环经常用来执行一组语句某一特定的次数。这里用<a
HREF="tutorial4_page4.htm">另一个循环</a>来演示如何作这项工作。</p>
<p><!-- PAGE X LINKS --><!-- this stuff checks if there are more pages in this story. if so, we'll
suck out the titles of those pages and build links. Right now, the maximum is
15 pages. -->第</font><font FACE="宋体" LANG="ZH-CN">1</font><font FACE="System,黑体"
LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4.htm"><font FACE="System,黑体" LANG="ZH-CN">第四课介绍</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- PAGE X LINKS --><!-- this stuff checks if there are more pages in this story. if so, we'll
suck out the titles of those pages and build links. Right now, the maximum is 15 pages. --><!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">2</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page2.htm"><font FACE="System,黑体" LANG="ZH-CN">循环介绍</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">3</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page3.htm"><font FACE="System,黑体" LANG="ZH-CN">循环的密码</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">4</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page4.htm"><font FACE="System,黑体" LANG="ZH-CN">再谈</font><font
FACE="宋体" LANG="ZH-CN">WHILE</font><font FACE="System,黑体" LANG="ZH-CN">循环</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">5</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page5.htm"><font FACE="宋体" LANG="ZH-CN">For </font><font
FACE="System,黑体" LANG="ZH-CN">循环</font></a><font FACE="System,黑体" LANG="ZH-CN"
SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">6</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page6.htm"><font FACE="System,黑体" LANG="ZH-CN">嵌套循环</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">7</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page7.htm"><font FACE="System,黑体" LANG="ZH-CN">循环练习</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">8</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page8.htm"><font FACE="System,黑体" LANG="ZH-CN">数组</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">9</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page9.htm"><font FACE="System,黑体" LANG="ZH-CN">数组和循环</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">10</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">:</font><a
HREF="tutorial4_page10.html"><font FACE="System,黑体" LANG="ZH-CN">文件目标模块中的数组</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">11</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page11.htm"><font FACE="System,黑体" LANG="ZH-CN">函数</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">12</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page12.html"><font FACE="System,黑体" LANG="ZH-CN">无参数函数</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">13</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page13.htm"><font FACE="System,黑体" LANG="ZH-CN">参数及返回值</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
<!-- this is a mini-template that formats each pageX link. So, if a story
has 15 pages, we need to generate 15 links to it. This is how each one
will look... --> </font><font FACE="System,黑体" LANG="ZH-CN">第</font><font FACE="宋体" LANG="ZH-CN">14</font><font
FACE="System,黑体" LANG="ZH-CN">页</font><font FACE="宋体" LANG="ZH-CN" SIZE="2">: </font><a
HREF="tutorial4_page14.htm"><font FACE="System,黑体" LANG="ZH-CN">多于一个参数的函数</font></a><font
FACE="System,黑体" LANG="ZH-CN" SIZE="2"><br>
</font><font FACE="System,黑体" LANG="ZH-CN"></p>
<p><br>
</p>
</font><font FACE="System,黑体" LANG="ZH-CN" SIZE="2"><p><br>
<!-- AUTHOR TAGLINE --> </font></td>
</tr>
</table>
<font FACE="System,黑体" LANG="ZH-CN">
<p> </p>
</font>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -