<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.t1 { width:400px; }
</style>
<script>
window.onload = function () {
var aInp = document.getElementsByTagName('input');
var iNow = null;
var iNew = null;
var t = 0;
var str = '';
var timer = null;
aInp[2].onclick = function () {
iNew = new Date(aInp[0].value);
clearInterval( timer );
timer = setInterval (function (){
iNow = new Date();
t = Math.floor( ( iNew - iNow ) / 1000 );
if ( t >= 0 ) {
str = Math.floor(t/86400)+'天'+Math.floor(t%86400/3600)+'时'+Math.floor(t%86400%3600/60)+'分'+t%60+'秒';
aInp[1].value = str;
} else {
clearInterval( timer );
}
}, 1000);
};
};
</script>
</head>
<body>
距离:<input class="t1" type="text" value="November 27,2013 22:3:0" /><br />
还剩:<input class="t1" type="text" />
<input type="button" value="开始倒计时吧" />
</body>
</html>
js倒计时
最新推荐文章于 2024-10-06 12:17:25 发布