日期和时间特效-倒计时效果
————————————————
<script type="text/javascript">
function start(){
setInterval(function(){
var now = new Date();
var end = new Date(now.getYear() + 1 + 1900,0,1);
var time = end.getTime() - now.getTime();
var str = getTimeTxt(time);
document.getElementById('left').innerHTML = '距离明年年元旦还剩:' + str;
},1000);
}
function getTimeTxt(time){
time /= 1000;
var days = time / (24*60*60);
var hour = time % (24*60*60) / (60*60);
var min = time % (24*60*60) % (60*60) / 60;
var sec = time % (24*60*60) % (60*60) % 60;
var str = '';
if(days > 0)
str += Math.floor(days)+'天';
if(hour > 0)
str += Math.floor(hour)+'时';
if(min > 0)
str += Math.floor(min)+'分';
str += Math.floor(sec)+'秒';
return str;
}
</script>
——————————————————————————
<body style="text-align:center">
<p>
<input type="button" value="进入倒计时" onclick="start();"/>
</p>
<h2 id="left"></h2>
</body>
————————————————————————————