时分秒计时
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>时间计时器</title>
</head>
<body>
<div id="time"></div>
</body>
<script>
function timer(hour, min, sec, ele) {
var hour = hour ? hour : 0;
var min = min ? min : 0;
var sec = sec ? sec : 0;
var init;
setInterval(() => {
sec = sec + 1;
if (sec >= 60) {
sec = 0;
min = min + 1;
}
if (min >= 60) {
min = 0;
hour = hour + 1;
}
var h = hour < 10 ? "0" + hour : hour;
var m = min < 10 ? "0" + min : min;
var s = sec < 10 ? "0" + sec : sec;
ele.innerText = h + ":" + m + ":" + s;
}, 1000);
}
timer(
3, // 时
39, // 分
45, // 秒
document.getElementById("time") // 节点
);
</script>
</html>