在Javascript給事件定時很容易。其關(guān)鍵指令是setTimeout()和clearTimeout()方法。利用setTimeout(), 指令可以在未來的某個指定時間執(zhí)行特定指令。如果你改變主意,你可以用clearTimeout()取消setTimeout的定時. 下面是setTimeout的基本格式:
var the_timeout = setTimeout("some javascript
statement", some_number_of_milliseconds);
在上面的例子中用到的指令如下:
var the_timeout = setTimeout("alertAndRedirect ();",3000);
<form name="the_form" >
<input type="text" name="the_text" />
</form>
<script language="javascript">
<!--
function doDumbTimer()
{
var timer1 = setTimeout("document.the_form.the_text.value='3 seconds!';",3000);
var timer2 = setTimeout("document.the_form.the_text.value='6 seconds!';",6000);
var timer3 = setTimeout("document.the_form.the_text.value='9 seconds!';",9000);
}
doDumbTimer();
-->
</script>
更多信息請查看IT技術(shù)專欄