<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<span id="a"></span>
<br/>
<input type="text" id="b" value="00小时00分钟00秒00"/>
<input type="button" id="c" value="开始" />
<input type="button" id="d" value="暂停" />
<input type="submit" id="e" value="重置" />
<script type="text/javascript">
var a = document.getElementById('a');
var b = document.getElementById('b');
var c = document.getElementById('c');
var d = document.getElementById('d');
var e = document.getElementById('e');
setInterval(function()
{
var d,s,m,c,t,z;
var time = new Date();
var stim = new Date(2050,1,31);
var ztrm = stim-time;
d = Math.floor(ztrm/1000/60/60/24);
s = Math.floor(ztrm/1000/60/60%24);
m = Math.floor(ztrm/1000/60%60);
t = Math.floor(ztrm/1000%60);
a.innerHTML="剩下:"+d+"天"+s+"小时"+m+"分钟"+t+"秒";
},1000)
var t;
var s=f=m=h=0;
c.onclick=function()
{
t=setInterval(aa,10);
c.disabled=true;
}
d.onclick=function()
{
clearInterval(t);
c.disabled=false;
}
e.onclick=function()
{
clearInterval(t);
b.value="00小时00分钟00秒00";
var s=f=m=h=0;
c.disabled=false;
}
function aa()
{
h+=1;
if (h>=100) {
m+=1;
h=0;
}
if (m>=60) {
f+=1;
m=0;
}
if (f>=60) {
s+=1
f=0;
}
b.value=s+"小时"+f+"分钟"+m+"秒"+h;
}
</script>
</body>
</html>
javascript(十八)秒表、倒计时
猜你喜欢
转载自blog.csdn.net/qq_38904347/article/details/82804119
今日推荐
周排行