📄 day3_2.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>
<script language="JavaScript">
<!-- hide me
function ringBell()
{
var timer1 = setTimeout("window.document.the_form.the_text.value='3 seconds!';", 3000);
var timer2 = setTimeout("window.document.the_form.the_text.value='6 seconds!';", 6000);
var timer3 = setTimeout("window.document.the_form.the_text.value='9 seconds!';", 9000);
}
// hide me -->
</script>
</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" rowspan="2"><small><small><br>
</small></small><strong>第二页:<font size="3" face="宋体">如何给事件定时</font></strong>
<p><font size="3"><font face="宋体">在Javascript给事件定时很容易。其关键指令是<tt>setTimeout()</tt><br>
和<tt>clearTimeout()</tt>方法。利用<tt>setTimeout()</tt>, 指令可以在未来<br>
的某个指定时间执行特定指令。如果你改变主意,你可以用<br>
<tt>clearTimeout()</tt>取消<tt>setTimeout</tt>的定时. </font></font></p>
<font size="3">
<p><font face="宋体">下面是<tt>setTimeout</tt>的基本格式: </font></p>
</font>
<blockquote>
<pre>var the_timeout = setTimeout("some javascript
statement", some_number_of_milliseconds);
</pre>
</blockquote>
<p><font size="3"><font face="宋体">在上面的例子中用到的指令如下:<br>
var the_timeout = setTimeout("alertAndRedirect ();",3000);<br>
<br>
该语句中有3项重要内容:</font></font>
<dl><font size="3">
<dt><font face="宋体"><tt>setTimeout</tt>返回一个值。在该语句中</font></dt>
</font>
<dd><font size="3"></font><font size="3"><font face="宋体"><tt>the_timeout</tt>是一个变量,它指向特定的<tt>setTimeout</tt>。<br>
如果你想取消该<tt>setTimeout</tt>的定时,你只需引用该变量<br>
即可。你可以给变量起一个别的名称。 </font></font></dd>
<font size="3">
<dt><font face="宋体">在<tt>setTimeout</tt>中用到的第1个变量是一个JavaScript 语句的字<br>
符串。</font></dt>
<dd><font face="宋体">在本例中第1个参数是字符串:<tt>"alertAndRedirect();"</tt></font>
<p><font face="宋体"><tt>alertAndRedirect</tt>是为载入一个提示框而编写的一个函<br>
数,当用户点击“OK”时还重新回到本页面。 </font></p>
<p><font face="宋体">注意在引号中的内容是一个完整的JavaScript语句,带有<br>
分号和其他必须的语法. 如果你执行该段代码则会调用函<br>
数<tt>alertAndRedirect</tt>。<tt>setTimeout</tt>只规定了该语句出现的<br>
时间。</font></p>
<p><font face="宋体">以下是函数<tt>alertAndRedirect()的代码:</tt> </font></p>
<blockquote>
<pre><font face="宋体">function alertAndRedirect()
{
alert('ok! exhale!');
window.location.replace("timing.htm");
}
</font></pre>
<dl>
<dt> </dt>
</dl>
</blockquote>
</dd>
<dt><font face="宋体"><tt>setTimeout</tt>的第2个参数指定了在多少毫秒之后执行第1个参数。</font></dt>
</font>
<dd><font size="3"></font><font size="3"><font face="宋体">一秒钟等于1000毫秒。所以如果你想让某事在秒钟之后发<br>
生你必须将第2个参数设置为3,000 毫秒。 </font></font></dd>
</dl>
<p> <font size="3"><font face="宋体">我们可以做下面的练习熟悉它的工作原理:</font></font></p>
<form name="the_form">
<p> <font size="2"></font><font size="2" face="宋体">
<input type="button" value="the bell tolls" onClick="ringBell();">
<input type="text" name="the_text" size="20">
</font></p>
</form>
<p><a href="day3_3.html">>></a></p>
<p><font face="宋体" size="3" color="#000000"><strong>JavaScript高级教程</strong></font><font color="#FF0000" face="宋体" size="3"><br>
</font><font face="宋体"><font color="#FF0000">第一页</font> <a href="day3_2.html">Javascript高级教程
- 第三课</a><br>
<font size="3"><font color="#FF0000">第二页</font> 如何给事件定时<br>
<font color="#FF0000">第三页</font> <a href="day3_3.html">定时循环的概念</a><br>
<font color="#FF0000">第四页</font> <a href="day3_4.html">定时循环的做法</a><br>
<font color="#FF0000">第五页</font> <a href="day3_5.html">一个Javascript编写的时钟</a><br>
<font color="#FF0000">第六页</font> <a href="day3_6.html">给定时器加入变量</a><br>
<font color="#FF0000">第七页</font> <a href="day3_7.html">识别用户的浏览器</a><br>
<font color="#FF0000">第八页</font> <a href="day3_8.html">如何识别用户的浏览器</a><br>
<font color="#FF0000">第九页</font> <a href="day3_9.html">对象和方法的识别</a><br>
<font color="#FF0000">第十页</font> <a href="day3_10.html">History对象</a></font></font></p>
<p><font size="3">[<a href="day1_1.html">第1课</a>][<a href="day2_1.html">第2课</a>][第3课][<a href="day4_1.html">第4课</a>][<a href="day5_1.html">第5课</a>]</font></p>
<hr align="left">
<!--webbot bot="Include" U-Include="../../copyright.html" TAG="BODY" startspan -->
<p><font face="verdana, arial, geneva, sans-serif" size="2"><a href="http://phtshop.yeah.net" target="_top">本文根据
网猴 相关文章改编,版权归原作者所有。</a> </font><font color="#000000"><span class="smallfont"></span></font></p>
<!--webbot bot="Include" endspan i-checksum="15926" --> </td>
</tr>
<tr> </tr>
</table>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -