应用代码一:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
setTimeout(txt,1000);
function txt(){
document.body.innerHTML = "<font color=red> OK " + parseInt(Math.random()*1000)+1 + "</font> ";
setTimeout(txt,1000);
}
//setInterval("txt()",1000); //用这个的话每间隔3000毫秒执行一次
//setTimeout(txt,3000); //用这个的话执行一次就不执行了
</script>
</head>
<body>
</body>
</html>
应用代码二:
<div id="time"></div>
<input type="button" οnclick="start_time()">开始计时</buttom>
<input type="button" οnclick="stop_time()">停止计时</buttom>
<input type="button" οnclick="reset_time()">重新计时</buttom>
<script language="javascript">
var i=0;
function start_time(){
i++;
time.innerHTML=i;
b=setTimeout("start_time()",1000);
}
function stop_time(){
clearTimeout(b)
}
function reset_time(){
i=0;
time.innerHTML=0;
}
</script>