html小小计时器

效果

在这里插入图片描述

代码

<!DOCTYPE html>
<html>
<head>
	<title>简易计时器</title>
	<script type="text/javascript">
		var init;
		var time = 0;
		function start1(){

			init = setInterval(timer,1000);
		}
		function timer(){
			time =time+1;
			document.getElementById("timetext").value = time;
		}
		function stop1(){
			clearInterval(init);
		}
		function reset1(){
			time = 0;
			document.getElementById("timetext").value = time;
		}
	</script>
</head>
<body>
	<input type="text" id="timetext" value="0" ><br>
	<input type="button" value="开始" id="submit" onclick="start1()">
	<input type="button" value="停止" id="stop" onclick="stop1()">
	<input type="reset" name="reset" id="reset" onclick="reset1()">
</body>
</html>

笔记

setInterval的使用,每隔一定时间调用函数

发布了98 篇原创文章 · 获赞 105 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_34691097/article/details/103277177