js倒计时显示实例
话不多说,请看实例代码
<!DOCTYPEhtml> <html> <head> <metacharset="UTF-8"> <title>js倒计时显示-细数逝去的过往</title> <styletype="text/css"> #clock{ font:bold24ptsans; background-color:#f5f5f5; padding:10px15px; border:1pxsolid#ccc; border-radius:5px; } .demo{ position:absolute; margin-left:40%; margin-top:40%; } </style> </head> <body> <divclass="demo"> <center> <h1>下班倒计时显示</h1> </center> <spanid="clock"></span> </div> <script> functiondisplayTime(){ varelt=document.getElementById("clock"); if(leftTime<0){ elt.innerHTML="Over"; }else{ varendTime=newDate("2016/11/2118:00:00"); varnow=newDate(); varleftTime=endTime.getTime()-now.getTime(); varms=parseInt(leftTime%1000).toString(); leftTime=parseInt(leftTime/1000); varo=Math.floor(leftTime/3600); vard=Math.floor(o/24); varm=Math.floor(leftTime/60%60); vars=leftTime%60; elt.innerHTML=o+"小时:"+m+"分:"+s+"秒:"+ms.charAt(0); setTimeout(displayTime,100); } } displayTime(); </script> </body> </html>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持毛票票!