<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript 倒计时设计demo</title>
<script>
window.onload = function(){
setInterval(wgc,1000);
wgc();
function wgc(){
var Time = new Date();
var Timeb = new Date(2016,4,10,17,37,0);
var t = Math.floor((Timeb-Time)/1000);
var str = Math.floor(t/86400) + '天' + Math.floor(t%86400/3600) + '时' + Math.floor(t%86400%3600/60) + '分' + t%60 + '秒';
var oDiv = document.getElementById('div1');
if(Time<Timeb){
oDiv.innerHTML = str;
}else{
oDiv.innerHTML = '结束了';
}
}
}
/*
天: Math.floor(t/86400)
时: Math.floor(t%86400/3600)
分: Math.floor(t%86400%3600/60)
秒: t%60
YuqiDai@G
*/
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>倒计时扩展版,设置时间</title>
<script>
window.onload = function(){
var Timeb = document.getElementById('timeb');
var But = document.getElementById('but');
var Timec = document.getElementById('time');
var t = Math.floor((new Date(Timeb) - new Date())/1000);
//alert(t);
But.onclick = function(){
Timebb = Timeb.value;
setInterval(ti,1000);
ti();
function ti(){
var t = Math.floor((new Date(Timebb) - new Date())/1000);
Timec.value = Math.floor(t/86400) + '天' + Math.floor(t%86400/3600)+ '时' + Math.floor(t%86400%3600/60) + '分' + t%60 +'秒';
}
}
}
</script>
</head>
<body>
距离:<input id="timeb" type="text" value="May 10,2016 18:50:00"/> <input id="but" type="button" value="开始倒计时"/><br><br>
还剩:<input id="time" type="text" disabled />
</body>
</html>
JavaScript 倒计时设计demo
最新推荐文章于 2022-05-25 15:31:50 发布