📄 day4_14.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><font face="宋体" size="3">这是我定义的一个数组:</font> <ul> <pre><font face="宋体">var monkeys = new Array("mattmarg","wendy","kristin","tim","aaron", "luke");var kittyphile = new Array("wendy", "ruby","roscoe", "tim");var discophile = new Array("mattmarg", "john travolta", "wendy");var happy = new Array("tim", "wendy","stimpy", "aaron");var cranky = new Array("ren", "mattmarg","luke");</font></pre> </ul> <p> </p> <p><font face="宋体" size="3">随着这些数组的定义,arrayIntersect函数给出,我们可轻<br> 而易举的发现那些网猴酷爱迪斯科:爱跳舞的网猴</font></p> <p><font face="宋体" size="3">注意到尽管John Travolta喜爱迪斯科,但他不在monkeys请<br> 单中,则他就不是只爱跳舞的网猴为调用该函数值,可这么来:</font> <ul> <pre><font face="宋体"><a href="#" onClick="arrayIntersect('dancing monkeys',monkeys,discophile);">dancing monkeys</a></font></pre> </ul> <p> </p> <p><font face="宋体" size="3">这是个具有3个参数的函数:一个代表交叉的姓名,第一个数组,<br> 及第二个数组。这也很容易发现爱猫的网猴名爱猫的网猴。</font></p> <p><font face="宋体" size="3">看一下源码:</font> <ul> <pre><font face="宋体"><a href="#" onClick="arrayIntersect('monkeys who love cats',monkeys,kittyphile);">cat-loving monkeys</a></font></pre> </ul> <p><font face="宋体" size="3">让我们看看arrayIntersect函数本身:</font> <ul> <pre><font face="宋体">function arrayIntersect(intersect_name, array_1, array_2){ var the_list = ""; for (loop_1 = 0; loop_1 < array_1.length; loop_1++) { for (loop_2 = 0; loop_2 < array_2.length; loop_2++) { if (array_1[loop_1] == array_2[loop_2]) { the_list = the_list + array_1[loop_1] + " "; } } } alert("the " + intersect_name + " are: "+ the_list);}</font></pre> </ul> <p><font face="宋体" size="3">看看你是否已经弄懂本例中的循环。关键是函数第一行:</font> <ul> <pre><font face="宋体">function arrayIntersect(intersect_name, array_1, array_2)</font></pre> </ul> <p><font face="宋体" size="3">这里定义了一个叫arrayIntersect的函数,它有3个参数。就象上<br> 例,每个参数就象一个变量,当函数调用时赋值。因此,当函数被调<br> 用时:</font> <ul> <pre><font face="宋体">arrayIntersect('dancing monkeys',monkeys,discophile);</font></pre> </ul> <p> </p> <p><font face="宋体" size="3">下列分配:</font> <font size="2"><ul> <li><font face="宋体">intersect_name = 'dancing monkeys' </font></li> <li><font face="宋体">array_1 = monkeys </font></li> <li><font face="宋体">array_2 = discophile </font></font></li> </ul> <p><font face="宋体" size="3">唯一需注意的是,你必须以正确的参数数目来调用函数。如果你一旦<br> 象这样调用arrayIntersect:</font> <ul> <pre><font face="宋体">arrayIntersect(monkeys,discophile);</font></pre> </ul> <p> </p> <font SIZE="3"><p ALIGN="JUSTIFY">将会出错。试一下看会发生什么错误。</p> <p ALIGN="JUSTIFY">在任一标准的<font face="宋体">Javascript</font>程序中,函数都是基本的部件。因此理解其<br> 工作原理极其重要。这里是一个测试你对这项工作理解多少的练习。<br> 再综合地做一下本课中其它练习,再在你自己的浏览器中应用。</p> </font><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_14.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day4_14.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://sun150-2.fimmu.edu.cn/doing/js1/day4_2.html">循环介绍</a></font><font size="2"><br> </font><font SIZE="3"><font color="#FF0000">第三页</font> <a href="day4_3.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day4_3.html">循环的密码</a></font><font size="2"><br> </font><font SIZE="3"><font color="#FF0000">第四页</font> <a href="day4_4.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/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://sun150-2.fimmu.edu.cn/doing/js1/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://sun150-2.fimmu.edu.cn/doing/js1/day4_6.html">嵌套循环</a></font><font size="2"><br> </font><font SIZE="3"><font color="#FF0000">第七页</font> <a href="day4_7.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day4_7.html">循环练习</a></font><font size="2"><br> </font><font SIZE="3"><font color="#FF0000">第八页</font> <a href="day4_8.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day4_8.html">数组</a></font><font size="2"><br> </font><font SIZE="3"><font color="#FF0000">第九页</font> <a href="day4_9.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day4_9.html">数组和循环</a></font><font size="2"><br> </font><font SIZE="3"><font color="#FF0000">第十页</font> <a href="day4_10.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day4_10.html">文件目标模块中的数组</a></font><font size="2"><br> </font><font SIZE="3"><font color="#FF0000">第十一页</font> <a href="day4_11.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day4_11.html">函数</a></font><font size="2"><br> </font><font SIZE="3"><font color="#FF0000">第十二页</font> <a href="day4_12.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day4_12.html">无参数函数</a></font><font size="2"><br> </font><font SIZE="3"><font color="#FF0000">第十三页</font> <a href="day4_13.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day4_13.html">参数及返回值</a></font><font size="2"><br> </font><font SIZE="3"><font color="#FF0000">第十四页</font> 多于一个参数的函数</font></p> <p align="left"><font face="宋体" size="3">[<a href="index.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/index.html">第1课</a>][<a href="day2_1.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day2_1.html">第2课</a>][<a href="day3_1.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day3_1.html">第3课</a>][第4课][<a href="day5_1.html" tppabs="http://sun150-2.fimmu.edu.cn/doing/js1/day5_1.html">第5课</a>]</font></p> <hr align="left"> <p><font size="2">本文由<a href="javascript:if(confirm('http://chd.126.com/ \n\n文件并未依 Teleport Pro 取回,因为 它的域或路径超过开始网址中设置的范围。 \n\n你要从服务器上打开它吗?'))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\n文件并未依 Teleport Pro 取回,因为 它的域或路径超过开始网址中设置的范围。 \n\n你要从服务器上打开它吗?'))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\n文件并未依 Teleport Pro 取回,因为 它的域或路径超过开始网址中设置的范围。 \n\n你要从服务器上打开它吗?'))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 + -