📄 day2_2.html
字号:
<td colspan="2">-<a href="../../1-teach/internet/index.htm">Internet应用</a></td>
</tr>
<tr>
<td colspan="2">-<a href="../../1-teach/photoshop/index.html">Photoshop</a></td>
</tr>
<tr>
<td colspan="2">-<a href="../../1-teach/flash/page1.html">Flash</a></td>
</tr>
<tr>
<td colspan="2">-<a href="../../1-teach/asp/index.html">ASP</a></td>
</tr>
<tr>
<td colspan="2">-<a href="../../1-teach/php/index.html">PHP</a></td>
</tr>
<tr>
<td colspan="2">-<a href="../../1-teach/java/index.htm">Java</a></td>
</tr>
<tr>
<td colspan="2">-<a href="../../1-teach/vb/index.htm">VB</a></td>
</tr>
<tr>
<td colspan="2">-<a href="../../1-teach/c/index.htm">C、C++</a></td>
</tr>
<tr>
<td colspan="2">-<a href="../../1-backend/database/php_mysql/index.html">PHP/MySQL</a></td>
</tr>
<tr>
<td colspan="2"><a href="../../1-backend/cgi_perl/perl_beginner/index.html">-Perl</a>
</td>
</tr>
<tr>
<td colspan="2">-<a href="../../1-teach/other/index.htm">其它</a> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#666699">
<div align="center"><font color="#FFFFFF">更多教程</font></div>
</td>
</tr>
<tr>
<td colspan="2" height="17"><a href="../../1hdml/index.html">-HDML</a></td>
</tr>
<tr>
<td colspan="2" height="23"><font face="宋体"><a href="../../1-backend/database/course/day1_1.html">-网络数据库</a></font></td>
</tr>
<tr>
<td colspan="2" height="14"><a href="../../1-backend/protocols/ping/index.html"><font face="arial, helvetica, sans-serif">Ping</font></a></td>
</tr>
<tr>
<td colspan="2" height="20"><a href="../../1-backend/cgi_perl/search_engine/index.html">-创建搜索引擎</a></td>
</tr>
<tr>
<td colspan="2" height="16">-<a href="../../1adobe/GoLive/index.html">Adobe GoLive</a></td>
</tr>
<tr>
<td colspan="2"><a href="../../1-backend/cgi_perl/templates/index.html">模板</a></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#666699"><font color="#FFFFFF">合作伙伴</font></td>
</tr>
<tr>
<td colspan="2" align="left">-<a href="http://www.5dmedia.com/" target="_blank">5D精英网</a></td>
</tr>
<tr align="center">
<td colspan="2"> <img src="../../Library/front_monkey.gif" width="59" height="68"></td>
</tr>
</tbody>
</table>
<br><!-- #EndLibraryItem --></td>
<!-- End of headlines (column 1: left column) --> <!-- Gutter between columns 1 and 2 -->
<td width="10" height="794"><img src="http://www.sohu.com/images/pixel.gif" width=10></td>
<!-- Search box and directories (columns 2 and 3: middle columns, combined into one) -->
<td align=center valign=top width="558">
<div align="left"><!-- #BeginEditable "1" -->
<title>javascrip教程</title>
<strong><font face="宋体" size="3">第二页:变量介绍</font></strong>
<p><font face="宋体" size="3">如果你学过代数,你一定见过变量。如果没学过也不要紧。变<br>
量是JavaScript存储信息的简单方式。例如,当你写:</font></p>
<p><font face="宋体" size="3">"x=2," "x"是一个变量,它存储值为2。如果而后你又说"y=x+3,"<br>
"y"将具有值“5”</font></p>
<p><font face="宋体" size="3">这里是一个使用变量的JavaScript例子。</font></p>
<p><font face="宋体" size="3"><b>在本例中我们一步一步浏览源码</b> 你将看到: </font></p>
<blockquote>
<pre><font face="宋体" size="3"><script language="JavaScript">
<!-- hide me
</font></pre>
</blockquote>
<p><font face="宋体" size="3">开始的这两行我们已经见过。这是任何JavaScript程序都必须<br>
的序曲。</font></p>
<blockquote>
<pre><font face="宋体" size="3">// load up some variables
var secs_per_min = 60;
var mins_per_hour = 60;
var hours_per_day = 24;
var days_per_year = 365;
</font></pre>
</blockquote>
<p><font face="宋体" size="3">第一行是一个注释。含义很明确。</font></p>
<p><font face="宋体" size="3">下几行是变量申明,有几样事情需注意:</font></p>
<p><font face="宋体" size="3">当首次用一变量时,应以“var”申明。</font>
<dl>
<dd><font face="宋体" size="3">尽管以var 作为变量申明严格说并不必要,但这是一个好<br>
习惯。当我们讨论接下来的两课时,我们将知道为什么。</font></dd>
<dt> </dt>
</dl>
<p><font face="宋体" size="3">变量必须以字母或强调性字符起始。</font>
<dl>
<dd><font face="宋体" size="3">第一个字符后,变量须有数字。因此<tt>monkey_23即是合法的<br>
变量名。</tt></font></dd>
</dl>
<p><font face="宋体" size="3">变量名多数是大小写敏感的,但对不同版本的JavaScript也不<br>
尽然。</font>
<dl>
<dd><font face="宋体"><font size="3">这意味着变量<tt>Loop</tt>和<tt>loop</tt></font><tt><font size="4">在有些浏览器中是不同的。一般<br>
情况下,建议坚持使用一种命名习惯并保持不变。我本人<br>
习惯使用变量间加下划线。其他人有喜欢变量间首字大<br>
写的,如</font><font size="3">secsPerMin</font></tt><font size="3">。</font></font></dd>
</dl>
<p><font face="宋体" size="3">变量应描述其目的。</font>
<dl>
<dd><font face="宋体" size="3">象 <tt>x</tt>, <tt>y</tt>, 或<tt>hack_hack_hack对想要了解你的语言的人来<br>
说没有什么用。别使变量名太长以致敲起来费劲,但要长<br>
到有一定的描述力。</tt></font></dd>
</dl>
<p><font face="宋体" size="3">在定义变量时就可赋于其一个值,也可今后在给出。</font>
<dl>
<dd><font face="宋体" size="3">在该例中每个变量开始定义时就被赋于了值。不一定非<br>
如此,今后的例子中我们将看到即使我们不知道其值,我<br>
们也可很好的定义它。</font></dd>
<dt> </dt>
<dt><font face="宋体" size="3">语句以半括弧结束。 </font></dt>
<dd><font face="宋体" size="3">语句是JavaScript的表达句,半括弧是结束标志。空格和<br>
空行是可被JavaScript编译器忽略的,他们仅是为人们读<br>
起来方便,该例可被写成长长的一行,但即使加上注释,<br>
看起来也会极其吃力。</font>
<p><font face="宋体" size="3">结束前我要提一下有时半括弧是不必须的,你可能也注意<br>
到有的人编的语句没有半括弧作为结束。但加上它是个好<br>
习惯,这不仅是由于你的程序的可读性会好的多,这也可<br>
减少空行,这些空行会塞满你的程序Webmonkey的习惯是<br>
在每一语句后加上半括弧作为结束。</font></p>
</dd>
</dl>
<p><font face="宋体" size="3">// do some calculations<br>
<br>
var secs_per_day = secs_per_min * mins_per_hour * hours_per_day;<br>
<br>
var secs_per_year = secs_per_day * days_per_year;<br>
<br>
</font></p>
<p><font face="宋体" size="3">这里我们看到了一些基本的算术。每当JavaScript执行了该<br>
语句,变量<tt>secs_per_year</tt>将是无论得到的什么数乘以60, 60,<br>
24, 和 365。以后,无论何时遇到<tt>变量</tt></font><tt><font face="宋体" size="4">secs_per_year,</font><font face="宋体" size="3">它<br>
将以这些巨大的数字替代。</font></tt></p>
<blockquote>
<pre><font face="宋体" size="3">// end hiding -->
</script>
</font></pre>
</blockquote>
<p><font face="宋体" size="3">这里没什么新鲜的,是一个JavaScript片的结束。</font></p>
<p><font face="宋体" size="3">这是该例中头文件中JavaScript的全部,当JavaScript执行这<br>
些代码时,上述变量将被定义。但此时这些变量尚未做任何<br>
事,这是在该例主体中要完成的事。<a href="day2_3.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 face="宋体" size="3"><font color="#FF0000">第一页</font>:第二天课程简介<br>
<font color="#FF0000">第二页</font>:变量介绍<br>
<font color="#FF0000">第三页</font>:<a href="day2_3.html">首个变量例子的程序主体</a><br>
<font color="#FF0000">第四页</font>:<a href="day2_4.html">字符串的魔力<br>
</a><font color="#FF0000">第五页</font>:<a href="day2_5.html">变量练习</a><a href="day2_4.html">
</a></font><font face="宋体" size="3"><br>
<font color="#FF0000">第</font><font face="宋体" size="3"><font color="#FF0000">六</font></font><font color="#FF0000">页</font>:<a href="day2_6.html">if-then子句</a><br>
<font color="#FF0000">第</font><font face="宋体" size="3"><font color="#FF0000">七</font></font><font color="#FF0000">页</font>:<a href="day2_7.html">if-then语句的例子</a>
<br>
<font color="#FF0000">第八页</font>:<a href="day2_9.html">链结事件</a><br>
<font color="#FF0000">第</font><font face="宋体" size="3"><font color="#FF0000">九</font></font><font color="#FF0000">页</font>:<a href="day2_10.html">图片交换</a><br>
<font color="#FF0000">第十页</font>:<a href="day2_12.html">复习</a><br>
</font></p>
<p align="left"><font face="宋体" size="3">[<a href="index.html">第1课</a>][第2课][<a href="day3_1.html">第3课</a>][<a href="day4_1.html">第4课</a>][<a href="day5_1.html">第5课</a>]</font></p>
<!-- #EndEditable --></div>
</td>
<!-- End of search box and directories (columns 2 and 3: middle columns, combined into one) -->
<!-- Gutter between columns 3 and 4 --> <!-- Other stuff (column 4: right column) -->
<!-- End of other stuff (column 4: right column) --> </tr>
</table>
<!-- End of table surrounding page contents -->
<hr noshade size=1 width=700>
<span class=eng><br>
Copyright (C) 1998-2000 Internet Technologies China. All rights reserved.
</span>
</center>
</body>
<!-- #EndTemplate --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -