进入页面从0开始正计时
<!DOCTYPE html>
<
html
lang
=
"en"
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
>
<
meta
charset
=
"utf-8"
/>
<
title
></
title
>
<
style
>
#mytime {
text-align: center;
}
</
style
>
<
script
>
function two_char(n) {
return n >= 10 ? n : "0" + n;
}
function time_fun() {
var sec=0;
setInterval(function () {
sec++;
var date = new Date(0, 0)
date.setSeconds(sec);
var h = date.getHours(), m = date.getMinutes(), s = date.getSeconds();
document.getElementById("mytime").innerText = two_char(h) + ":" + two_char(m) + ":" + two_char(s);
}, 1000);
}
</
script
>
</
head
>
<
body
onload
=
"time_fun()"
>
<
h1
id
=
"mytime"
>00:00:00</
h1
>
</
body
>
</
html
>
注意:有道等翻译软件自动将网页由英文转换为中文会导致计时器中英文(数字与汉字)切换问题