js实现动态时钟

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<img src="img/0.png" id="h1">
		<img src="img/0.png" id="h2">
		<span>:</span>
		<img src="img/0.png" id="m1">
		<img src="img/0.png" id="m2">
		<span>:</span>
		<img src="img/0.png" id="s1">
		<img src="img/0.png" id="s2">
	</body>
</html>
<script type="text/javascript">
	function fun(){
		var d = new Date();
		var _h=d.getHours();
		var _mm=d.getMinutes();
		var _s=d.getSeconds();
		h1.src="img/"+parseInt(_h/10)+".png"
		h2.src="img/"+(_h%10)+".png"
		m1.src="img/"+parseInt(_mm/10)+".png"
		m2.src="img/"+(_mm%10)+".png"
		s1.src="img/"+parseInt(_s/10)+".png"
		s2.src="img/"+(_s%10)+".png"
	}
	setInterval(fun,1000);
</script>

效果如下:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44963099/article/details/89738564