——执行代码
setTimeout() //指定延迟时间
<!DOCTYPE HTML> <html> <head> <script type="text/javascript"> function tinfo(){ var t=setTimeout("alert('Hello!')",5000); } </script> </head> <body> <form> <input type="button" value="start" onClick="tinfo()"> </form> </body> </html>
clearTimeout() //
setInterval() //每隔指定的时间
setInterval(代码,交互时间)
e.g:
<script type="text/javascript">
var attime;
function clock(){
var time=new Date();
attime=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds() ;//获取时;分;秒
document.getElementById("clock").value = attime;
}
setInterval(clock,100);//显示动态时间
</script>
<form>
<input type="text" id="clock" size="50" />
</form>
clearInterval() //
<script type="text/javascript"> function clock(){ var time=new Date(); document.getElementById("clock").value = time; } // 每隔100毫秒调用clock函数,并将返回值赋值给i var i=setInterval("clock()",100); </script>
<form>
<input type="text" id="clock" size="50" />
<input type="button" value="Stop" onclick="clearInterval(i)" />
</form>