<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>定时器</title>
<style type='text/css'>
#box {width:80px; height:80px; background:#f00; position:absolute; left:50px; top:50px;}
</style>
<script>
var $time;
function $(id){
return document.getElementById(id);
}
function start(){
$("span").innerHTML=parseInt($("span").innerHTML)+1;
$time=setTimeout('start()',1000);
}
window.onload = function() {
$("start").onclick=function(){
start();
}
$("end").onclick=function(){
//取消定时器
clearTimeout($time);
$("span").innerHTML=1;
}
}
</script>
</head>
<body>
<span id="span">1</span><br/>
<input type="button" id="start" value="开始" /><br/>
<input type="button" id="end" value="结束" /><br/>
</body>
</html>
为制作动态时间程序作基础