Maison  >  Article  >  php教程  >  JS时间倒计时

JS时间倒计时

WBOY
WBOYoriginal
2016-06-07 11:43:351305parcourir

js 倒计时,刚刚用到就直接发上来
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br> <br> <br> <meta> <br> <title>JS时间倒计时</title> <br> <script><br /> <br /> <br /> var time_now_server,time_now_client,time_end,time_server_client,timerID;<br /> <br /> //结束时间<br /> time_end=new Date("2014/10/31 09:00:00");<br /> time_end=time_end.getTime();<br /> //开始的时间:如果不填入时间日期默认为当前的日期时间<br /> time_now_server=new Date;<br /> time_now_server=time_now_server.getTime();<br /> <br /> time_now_client=new Date();<br /> time_now_client=time_now_client.getTime();<br /> <br /> time_server_client=time_now_server-time_now_client;<br /> <br /> setTimeout("show_time()",1000);<br /> <br /> <br /> //显示时间函数<br /> function show_time()<br /> {<br /> var timer = document.getElementById("timer");<br /> if(!timer){<br /> return ;<br /> }<br /> timer.innerHTML =time_server_client;<br /> <br /> var time_now,time_distance,str_time;<br /> var int_day,int_hour,int_minute,int_second;<br /> var time_now=new Date();<br /> time_now=time_now.getTime()+time_server_client;<br /> time_distance=time_end-time_now;<br /> if(time_distance>0)<br /> {<br /> int_day=Math.floor(time_distance/86400000)<br /> time_distance-=int_day*86400000;<br /> int_hour=Math.floor(time_distance/3600000)<br /> time_distance-=int_hour*3600000;<br /> int_minute=Math.floor(time_distance/60000)<br /> time_distance-=int_minute*60000;<br /> int_second=Math.floor(time_distance/1000)<br /> <br /> if(int_hour<10){<br /> int_hour="0"+int_hour;<br /> }<br /> if(int_minute<10){<br /> int_minute="0"+int_minute;<br /> }<br /> if(int_second<10){<br /> int_second="0"+int_second;<br /> }<br /> <br /> str_time=int_day+"天"+int_hour+"小时"+int_minute+"分钟"+int_second+"秒";<br /> timer.innerHTML=str_time;<br /> setTimeout("show_time()",1000);<br /> <br /> }<br /> else<br /> {<br /> <br /> timer.innerHTML =timer.innerHTML;<br /> clearTimeout(timerID)<br /> window.location.href="http://www.baidu.com";<br /> }<br /> }<br /> </script><br> <br>  <br> <br> <div></div> <br> <br> <div></div> <br> <br>

AD:真正免费,域名+虚机+企业邮箱=0元

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn