js计时器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nanshan_hzq/article/details/50684254
<html> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<head> 
<script type="text/javascript"> 
var c=0 
var t 
function timedCount() 
document.getElementById('txt').value=c 
c=c+1 
t=setTimeout("timedCount()",1000) 
function stopCount() 
clearTimeout(t) 
</script> 
</head> 
<body> 
<form> 
<input type="button" value="ߪʼ݆ʱá" onClick="timedCount()"> 
<input type="text" id="txt"> 
<input type="button" value="ֹ݆ͣʱá" onClick="stopCount()"> 
</form> 
<p>ȫ֣ܷʏĦքpߪʼ݆ʱqдť4Ǵ݆֯ʱǷcˤɫ࠲ܡһֱ޸ѐ݆ʱìՓ 0 ߪʼc֣ܷpֹ݆ͣʱqдťࠉӔוֹ݆ʱc</p> 
<p>timedCount(),1000msַؔܺؔܺc</p> 
</body> 
</html> 

猜你喜欢

转载自blog.csdn.net/nanshan_hzq/article/details/50684254