setInterval()每隔一定时间执行函数
clearInterval(index)根据返回过来的setInterval()的id清除定时执行事件
setTimeOut()隔一定时间后执行一次函数
范例代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
function fun1(){
alert("每隔3秒弹出一次");
}
var timer = null;
function fun2(){
timer=window.setInterval("fun1()",3000);
}
function fun3(){
alert("关闭方法");
window.clearInterval(timer);
}
function fun4(){
window.setTimeout("fun1()",1000);
}
</script>
<input type="button" οnclick="fun2()" value="setInterval()方法"/>
<input type="button" οnclick="fun3()" value="setInterval()关闭方法"/>
<input type="button" οnclick="fun4()" value="setTimeOut()方法"/>
</body>
</html>