gpt4 book ai didi

JavaScript 时钟字体大小

转载 作者:行者123 更新时间:2023-12-01 01:54:33 25 4
gpt4 key购买 nike

如何才能使小时 (h) 和秒 (s) 字体大小更小,如 40px,分钟 (m) 字体大小更大,如 68px?这不起作用。

<script>
function startTime() {
var today = new Date();
var h = today.getUTCHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);


var hh = h.fontsize("40px");
var mm = m.fontsize("68px");
var ss = s.fontsize("40px");
document.getElementById('ora').innerHTML =
hh + ":" + mm + ":" + ss;
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i};
return i;
}
</script>

最佳答案

HTML:

<div id="hours">

</div>
<div id="minutes">

</div>
<div id="seconds">

</div>

CSS:

#hours, #seconds{
font-size: 40px;
}

#minutes{
font-size: 68px;
margin: 0 20px 0 20px;
}

div{
display: inline-block;
}

JavaScript:

   function startTime() {
var today = new Date();
var h = today.getUTCHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);

document.getElementById('hours').innerHTML = h;
document.getElementById('minutes').innerHTML = m;
document.getElementById('seconds').innerHTML = s;
var t = setTimeout(startTime, 500);
}

function checkTime(i) {
if (i < 10) {i = "0" + i};
return i;
}

JSFiddle Demo

关于JavaScript 时钟字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51148235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com