在javascript給事件定時(shí)很容易。其關(guān)鍵指令是settimeout()和cleartimeout()方法。利用settimeout(), 指令可以在未來的某個(gè)指定時(shí)間執(zhí)行特定指令。如果你改變主意,你可以用cleartimeout()取消settimeout的定時(shí). 下面是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>