<!DOCTYPE html>
<html>
<head>
	<title>Green Digital Clock</title>
	<style type="text/css">
		body {
			background-color: green;
			font-size: 80px;
			font-weight: bold;
			color: black;
			text-align: center;
		}
	</style>
</head>
<body onload="startTime()">
	<div id="clock"></div>
<pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
	function startTime() {
		var today = new Date();
		var h = today.getHours();
		var m = today.getMinutes();
		var s = today.getSeconds();
		var ms = today.getMilliseconds();
		m = checkTime(m);
		s = checkTime(s);
		ms = checkMilliseconds(ms);
		document.getElementById('clock').innerHTML = h + &quot;:&quot; + m + &quot;:&quot; + s + &quot;:&quot; + ms;
		var t = setTimeout(startTime, 1);
	}

	function checkTime(i) {
		if (i &lt; 10) {
			i = &quot;0&quot; + i
		};  // add zero in front of numbers &lt; 10
		return i;
	}

	function checkMilliseconds(i) {
		if (i &lt; 10) {
			i = &quot;00&quot; + i
		} else if (i &lt; 100) {
			i = &quot;0&quot; + i
		};  // add zeros in front of numbers &lt; 100
		return i;
	}
&lt;/script&gt;
</code></pre>
</body>
</html>
写一个绿色背景的电子时钟的html5要去:毫秒级字体颜色黑色

原文地址: https://www.cveoy.top/t/topic/0oi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录