admin 管理员组文章数量: 1086866
JS倒计时
人生最重要的是树立一个远大的目标,并下定决心去实现它. (歌德)
Index.html
<!DOCTYPE html>
<html><head> <meta charset="utf-8" /> <title>倒计时</title> <script>
function toTwo(n)
{if(n>9){return ''+n; }else{return '0'+n; }
}
window.onload=function(){var oBox=document.getElementById('box');var aImg=oBox.getElementsByTagName('img');function time(){var enddate=new Date('2016/12/25 00:00:00');var mydate=new Date(); var str='';var t=enddate.getTime()-mydate.getTime();str=toTwo(Math.floor(t/1000/60/60/24))+toTwo(Math.floor(t/1000/60/60%24))+toTwo(Math.floor(t/1000/60%60))+toTwo(Math.floor(t/1000%60));for(var i=0;i<aImg.length;i++){aImg[i].src='images/'+str[i]+'.png'; }}time();setInterval(time,1000);};
</script> <style>
#box { width:1000px;height:200px;font-size:14px;line-height:100px;margin:auto;}#box img{ width:30px;height:60px;}
</style> </head> <body> <div id="box"> <img src="images/0.png" /> <img src="images/0.png" /> 天: <img src="images/0.png" /> <img src="images/0.png" /> 时: <img src="images/0.png" /> <img src="images/0.png" /> 分: <img src="images/0.png" /> <img src="images/0.png" /> 秒</div> </body>
</html>
运行结果如图:
本文标签: JS倒计时
版权声明:本文标题:JS倒计时 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1697135245a262104.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论