标签:time() idt 1.0 init time func imu har tin
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>当前时间为:<span id="timeNow">00:00:00</span></div>
<button id="timeBegin">计时开始</button>
<button id="timeEnd">计时结束</button>
<button id="timeClear">计时清除</button>
<script>
//定义初始值 计时器
var timer = "";
//开始计时
var beginBtn = document.getElementById("timeBegin");
var endBtn = document.getElementById("timeEnd");
var clearBtn = document.getElementById("timeClear");
var min,second,millisecond;//分 秒 毫秒
min= second=millisecond=0; //初始化
function time() {
millisecond+=50;
if (millisecond >= 1000) {
millisecond=0
second += 1;
}
if (second >= 60) {
second=0
min += 1;
}
counts = min + ‘:‘ + second + ‘:‘ + millisecond;
document.getElementById("timeNow").innerText = counts;
}
//开始计时
function BeginTime() {
beginBtn.onclick = function () {
timer = setInterval(time, 50);
}
}
//结束计时
function EndTime() {
endBtn.onclick = function () {
clearInterval(timer);
}
}
//计时清除
function ClearTime() {
clearBtn.onclick = function () {
document.getElementById("timeNow").innerHTML = "00:00:00";
}
}
BeginTime();
EndTime();
ClearTime()
</script>
</body>
</html>
标签:time() idt 1.0 init time func imu har tin
原文地址:https://www.cnblogs.com/shenbo666/p/9522578.html