就是个倒计时JS,
我这段代码不知道怎么的,刷新一次后就出错误,请高手帮忙看看
<!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>倒计时</title>
<style type="text/css">
*{margin:0;padding:0;}
.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;}
</style>
</head>
<body><div class="content">
<h1>限时抢购啦!</h1>
<p>还剩<span id="times"><SCRIPT LANGUAGE="JavaScript">
function _fresh()
{
    var endtime=new Date("2011/8/28,12:20:12");
    var nowtime = new Date();
    var leftsecond=parseInt((endtime.getTime()-nowtime.getTime())/1000);
    __d=parseInt(leftsecond/3600/24);
    __h=parseInt((leftsecond/3600)%24);
    __m=parseInt((leftsecond/60)%60);
    __s=parseInt(leftsecond%60);
    document.write(__d+"天 "+__h+"小时"+__m+"分"+__s+"秒");
    
    if(leftsecond<=0){
    document.write("end");
    
    clearInterval(sh);
    }
}
_fresh()
var sh;
sh=setInterval(_fresh,1000);
</SCRIPT></span></p></div>
</body>
</html>

解决方案 »

  1.   

    <!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>倒计时</title>
    <style type="text/css">
    *{margin:0;padding:0;}
    .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;}
    </style>
    </head>
    <body>
    <div class="content">
    <h1>限时抢购啦!</h1>
    <p>还剩<span id="times"></span></p>
    </div><SCRIPT LANGUAGE="JavaScript">
    function _fresh()
    {
        var endtime=new Date("2011/8/28,12:20:12");
        var nowtime = new Date();
        var leftsecond=parseInt((endtime.getTime()-nowtime.getTime())/1000);
        __d=parseInt(leftsecond/3600/24);
        __h=parseInt((leftsecond/3600)%24);
        __m=parseInt((leftsecond/60)%60);
        __s=parseInt(leftsecond%60);
        document.getElementById('times').innerHTML = __d+"天 "+__h+"小时"+__m+"分"+__s+"秒";
        
        if(leftsecond<=0){
        document.getElementById('times').innerHTML = "end";
        
        clearInterval(sh);
        }
    }
    _fresh()
    var sh;
    sh=setInterval(_fresh,1000);
    </SCRIPT>
    </body>
    </html>
      

  2.   

    再多问一点哈,这个JS里面,截止时间是手动输入的,如何能引入参数呢?无论是PHP或其他语言参数
      

  3.   

    <!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>倒计时</title>
    <style type="text/css">
    *{margin:0;padding:0;}
    .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;}
    </style>
    </head>
    <body>
    <div class="content">
    <h1>限时抢购啦!</h1>
    <p>还剩<span id="times"></span></p>
    </div><SCRIPT LANGUAGE="JavaScript">
    function _fresh(endtime)
    {
        //var endtime=new Date("2011/8/28,12:20:12");
    endtime = new Date(endtime);
        var nowtime = new Date();
        var leftsecond=parseInt((endtime.getTime()-nowtime.getTime())/1000);
        __d=parseInt(leftsecond/3600/24);
        __h=parseInt((leftsecond/3600)%24);
        __m=parseInt((leftsecond/60)%60);
        __s=parseInt(leftsecond%60);
        document.getElementById('times').innerHTML = __d+"天 "+__h+"小时"+__m+"分"+__s+"秒";
        
        if(leftsecond<=0){
        document.getElementById('times').innerHTML = "end";
        
        clearInterval(sh);
        }
    }
    var sh;
    var endtime = '2011/8/28,12:20:12';
    sh=setInterval('_fresh(endtime)',1000);
    </SCRIPT>
    </body>
    </html>