写一个绿色背景的电子时钟的html5要去:毫秒级字体颜色黑色
<!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><script type="text/javascript">
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 + ":" + m + ":" + s + ":" + ms;
var t = setTimeout(startTime, 1);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i
}; // add zero in front of numbers < 10
return i;
}
function checkMilliseconds(i) {
if (i < 10) {
i = "00" + i
} else if (i < 100) {
i = "0" + i
}; // add zeros in front of numbers < 100
return i;
}
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/0oi 著作权归作者所有。请勿转载和采集!