<!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=gb2312" />
<title>setTimeOut() & setInterval()</title>
<script type="text/javascript">
var i=0;
var t;
function timeOut(){
i=i+1;
var textValue=window.document.getElementById("testTimeout");
textValue.value=i;
t=window.setTimeout(timeOut,200);//window.setTimeout('timeOut()',200);
}
var j=0;
var q;
function startTimeOut(){
q=window.setInterval('timeInterval()',200);
}
function timeInterval(){
j=j+1;
var textValue=window.document.getElementById("testInterval");
textValue.value=j;
}
</script>
</head>
<body>
<table border="1" height="200px" width="200px" background="black">
<tr>
<td>
<input id="testTimeout"/>
</td>
</tr>
</table>
<input type="button" οnclick="timeOut();" value="star"/>
<input type="button" οnclick="window.clearTimeout(t);" value="stop"/>
<table border="1" height="200px" width="200px" background="black">
<tr>
<td>
<input id="testInterval"/>
</td>
</tr>
</table>
<input type="button" οnclick="startTimeOut();" value="star"/>
<input type="button" οnclick="window.clearInterval(q);" value="stop"/>
</body>
</html>
setInterval() && setTimeout()
最新推荐文章于 2020-01-17 16:06:49 发布