js写计时器

在这里插入图片描述

<!DOCTYPE html>
<html leng = 'en'>
 	<head>
  		<meta charset = 'UTF-8'/>	
		<style>
			input{
    
    
				border:1px solid rgba(0,0,0,0,8);
				text-align:right;
				font-size:20px;
				font-weight:bold;
			}
		</style>
	 </head>
	 <body>
		minutes:<input type = 'text' value = '0'>
		seconds:<input type = 'text' value = '0'>
		<script>
			var input1 = document.getElementsByTagName('input')[0];
			var input2 = document.getElementsByTagName('input')[1];
			var timer = setInterval(function (){
    
    
				if(Number(input1.value) != 3){
    
    
					if(Number(input2.value) < 59){
    
    
						input2.value = Number(input2.value) +1;
					}else{
    
    
						input2.value = 0;
						input1.value = Number(input1.value) +1;
					}
				}else{
    
    
					clearInterval(timer);
				}
			},100);
		</script>
 	</body>
</html>





					

猜你喜欢

转载自blog.csdn.net/weixin_48727085/article/details/107791782