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>

效果如下:

在这里插入图片描述

你可能感兴趣的:(javascript)