间隔:
window.setInterval("要执行的代码",间隔的毫秒数)
window.clearInterval(间隔的id); 循环一次之后用来清除隔几秒执行的代码
?
<!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>
<input type="button" value="开始" onClick="start()" />
<input type="button" value="停止" onClick="end()" />
</body>
</html>
<script>
function show(){
alert("hello");
}
var id;
function start(){
id = window.setInterval("show()",1000);
}
function end(){
window.clearInterval(id);
}
</script>
?
延迟一段时间执行某一段代码(函数):window.setTimeout("要执行的代码",延迟的毫秒数)
使用延迟来做到间隔的效果:
function show(){
alert("hello");
window.setTimeout("show()",1000);
}
show();