📄 day4_3.html
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312-80">
<style type="text/css">
<!--
a:link { color: blue; text-decoration: none}
a:visited { color: purple; text-decoration: none}
a:hover { color: #CC0033; text-decoration: underline}
-->
</style>
<title>JavaScript教程</title>
</head>
<body topmargin="1" leftmargin="2">
<table border="0" width="591" cellspacing="0">
<tr>
<td bgcolor="#ffff99" width="451">JavaScript教程 - 第四课</td>
</tr>
<tr>
<td bgcolor="#FF6600" width="451"><a href="mailto:thau@wired.com">Thau</a></td>
</tr>
</table>
<div align="left">
<table border="0" width="630" cellspacing="0">
<tr>
<td width="458" valign="top" align="left"><strong><small><small><br>
</small></small><font face="宋体" size="3">第三页:</font><font SIZE="3">循环的密码</font></strong>
<p>那就是密码!</p>
<p>让我们逐行地来研究这个例子,如果你想看整个答案,可以查看源码。</p>
<p>在这个典型的<font face="宋体" size="3">Java script</font><font SIZE="3">序言之后,我们从双变量申报开始:</font></p>
<font SIZE="3"><blockquote>
<p><font size="2"><br>
</font><font size="2" face="verdana, arial, geneva, sans-serif">var password="pass
the wrench";<br>
<br>
var answer;<br>
<br>
</font></font></p>
</blockquote>
<p><font SIZE="3">这里我们定义该密码作为一个字符串,我们申报一个称为</font><br>
answer<font SIZE="3">的变量。你将理解为什么我们不得不立即申报一<br>
个</font>answer。下面几行是非常重要的:</p>
<blockquote>
<p><font size="2"><br>
</font><font size="2" face="verdana, arial, geneva, sans-serif">while (answer != password)
<br>
<br>
{<br>
<br>
answer = prompt("What's the woyd?","");<br>
<br>
}<br>
<br>
</font></p>
</blockquote>
<p>这是一个<font SIZE="3" face="宋体">while</font><font SIZE="3">循环。</font><font
SIZE="3" face="宋体">while </font><font SIZE="3">循环的一般格式为:</font></p>
<font SIZE="3"><blockquote>
<p><font size="2"><br>
</font><font size="2" face="verdana, arial, geneva, sans-serif">while (some test is true)<br>
<br>
{<br>
<br>
do the stuff inside the curly braces<br>
<br>
}<br>
<br>
</font></font></p>
</blockquote>
<p><font SIZE="3">上述几行表明:“当</font><font SIZE="3" face="宋体">answer</font><font
SIZE="3">不等价于</font><font SIZE="3" face="宋体">Password</font><font SIZE="3">时,执行提示<br>
命令。”这一循环将持续地执行波形括号内的语句直至测试<br>
失败。在使用者输入的单词与密码一致</font><font SIZE="3" face="宋体">(</font><font
SIZE="3">即</font><font SIZE="3" face="宋体">Pass the wrench)</font><font SIZE="3">的<br>
情况下,测试必将失败。</font></p>
<p><font SIZE="3">由于在对一个未申报的变量执行一个如</font><font SIZE="3"
face="宋体">(answer!=password)</font><font SIZE="3">的<br>
测试时,在某些浏览器上会产生错误,所以我们必须申<br>
报</font><font SIZE="3" face="宋体">answer</font><font SIZE="3">。由于在</font><font
SIZE="3" face="宋体">while</font><font SIZE="3">循环中将通过提示方案对</font><font
SIZE="3" face="宋体">answer</font><font SIZE="3">赋值,<br>
在我们第一次进行循环中,</font><font SIZE="3" face="宋体">answer</font><font
SIZE="3">将没有数值。提前定义它并<br>
设定其处始值为“”。</font></p>
<p><font SIZE="3">由于不定义循环经常地使用,循环经常用来执行一组语句某一<br>
特定的次数。这里用<a href="day4_4.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_4.html">另一个循环</a>来演示如何作这项工作。</font></p>
<p align="left"><font face="宋体" size="3" color="#000000"><strong>JavaScript教程</strong></font><font
color="#FF0000" face="宋体" size="3"><br>
</font><font size="3" color="#FF0000">第一页</font><font size="2" face="宋体"> </font><a
href="day4_3.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_3.html"><font SIZE="3">第四课介绍</font></a><font size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第二页</font> <a href="day4_2.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_2.html">循环介绍</a></font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第三页</font> 循环的密码</font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第四页</font> <a href="day4_4.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_4.html">再谈<font
face="宋体">WHILE</font>循环</a></font><font size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第五页</font> <a href="day4_5.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_5.html">For循环</a></font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第六页</font> <a href="day4_6.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_6.html">嵌套循环</a></font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第七页</font> <a href="day4_7.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_7.html">循环练习</a></font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第八页</font> <a href="day4_8.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_8.html">数组</a></font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第九页</font> <a href="day4_9.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_9.html">数组和循环</a></font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第十页</font> <a href="day4_10.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_10.html">文件目标模块中的数组</a></font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第十一页</font> <a href="day4_11.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_11.html">函数</a></font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第十二页</font> <a href="day4_12.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_12.html">无参数函数</a></font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第十三页</font> <a href="day4_13.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_13.html">参数及返回值</a></font><font
size="2"><br>
</font><font SIZE="3"><font color="#FF0000">第十四页</font> <a href="day4_14.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_14.html">多于一个参数的函数</a></font></p>
<p align="left"><font face="宋体" size="3">[<a href="index.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/index.html">第1课</a>][<a
href="day2_1.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day2_1.html">第2课</a>][<a href="day3_1.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day3_1.html">第3课</a>][第4课][<a
href="day5_1.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day5_1.html">第5课</a>]</font></p>
<hr align="left">
<p><font size="2">本文由<a href="javascript:if(confirm('http://chd.126.com/ \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://chd.126.com/'" tppabs="http://chd.126.com/" target="_blank">《</font><font
face="verdana, arial, geneva, sans-serif" size="2">CHD</font><font size="2">的网络教室》</a>根据<a
href="javascript:if(confirm('http://www.webmonkey.com.cn/ \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.webmonkey.com.cn/'" tppabs="http://www.webmonkey.com.cn/" target="_blank">《网猴》</a>相关文章改编,版权归<a
href="javascript:if(confirm('http://www.webmonkey.com.cn/ \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.webmonkey.com.cn/'" tppabs="http://www.webmonkey.com.cn/" target="_blank">《网猴》</a>所有</font></td>
</tr>
</table>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -