在javascript给事件定时很容易。其关键指令是settimeout()和cleartimeout()方法。利用settimeout(), 指令可以在未来的某个指定时间执行特定指令。如果你改变主意,你可以用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>
2025国考·省考课程试听报名