Home > php教程 > php手册 > body text

JS时间倒计时

WBOY
Release: 2016-06-07 11:43:35
Original
1293 people have browsed it

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元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!