吴伟贤のBlog

Feed Rss

js倒计时

05.03.2011, js, by .
[cce_html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>距离7月4日第二届冠军训练营</title> 
<style type="text/css"> 
*{margin:0;padding:0;} 
body{ text-align:center;} 
#content{width:300px;margin:0 auto;padding:10px;background:#eee;border:1px solid #999;} 
#content p span{color:red;font:bold 20px Arial;} 
#content p a{font:12px/23px '宋体';color:#888;} 
.div1{ display:none;} 
</style> 
</head> 
<body> 
<div style="color:#FFF; font-size:24px; font-weight:bold; background-color:#F00; height:40px; line-height:40px">距离7月4日第二届冠军训练营,还有→<span id="times"></span></div> 
<SCRIPT LANGUAGE="JavaScript"> 
function fresh() 
{ 
        var endtime=new Date("2011/07/04,10:00:00"); 
        var nowtime = new Date(); 
        var leftsecond=parseInt((endtime.getTime()-nowtime.getTime())/1000); 
        d=parseInt(leftsecond/3600/24); 
        h=parseInt((leftsecond/3600)%24); if(h<10){ h="0"+h} 
        m=parseInt((leftsecond/60)%60);       if(m<10){ m="0"+m} 
        s=parseInt(leftsecond%60);           if(s<10){ s="0"+s}
        document.getElementById("times").innerHTML=d+"天"+" "+h+"小时"+" "+m+"分"+" "+s+"秒"; 
        if(leftsecond<=0){ 
        document.getElementById("times").innerHTML="活动已结束"; 
        clearInterval(sh); 
        } 
} 
fresh() 
var sh; 
sh=setInterval(fresh,1000); 
</SCRIPT> 
</body> 
</html>
[/cce_html]

评论已关闭。