4
回答
倒计时这样写会飙高CPU怎么回事,哪里写错了
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="DAYU">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></scrip>
</head>

<body>
<?php
//3天后的时间
$d =strtotime('+1 days');
$threeday=date('Y-m-d H:i:s',$d);
?>
<span id="id1" style="display:none;"><?=$threeday;?></span>
<label id="showLeft">这里显示剩余时间</label> 
<script>
            var     dt = $("#id1").text();
            var     strArr  = dt.split(" ");
            var     strDay  = strArr[0].split("-");
            var     strTime = strArr[1].split(":");
            //document.write(strDay[0]+strDay[1]+strDay[2]+strTime[0]+strTime[1]+strTime[2]);
            //这个函数是倒计时
             function djs(){
                 minutes = 1000 * 60;
                 hours   = minutes  * 60;
                 days    = hours  * 24;
                //var years   = days * 365;                
                 date1   = new Date(); 
                 date2   = new Date(Date.UTC(strDay[0], strDay[1]-1, strDay[2], strTime[0]-8, strTime[1], strTime[2]));
                 minudt  = date2 - date1;
                //var y       = Math.floor(minudt/years);
                 d       = Math.floor(minudt/days); 
                 h       = Math.floor((minudt - d * days)/hours);
                 m       = Math.floor((minudt - d * days - h * hours)/minutes);
                 s       = Math.floor((minudt - d * days - h * hours - m * minutes)/1000);
                document.getElementById("showLeft").innerHTML=d + "天" + h +  "时" + m + "分" + s + "秒";
                //document.all.showLeft.innerHTML=d + "天" + h +  "时" + m + "分" + s + "秒";
                setInterval("djs()",1000);
            }
           djs();//占CPU
</script>    
</body>
</html>
举报
ahkxhyl
发帖于5年前 4回/388阅
共有4个答案 最后回答: 5年前

用这个就OK了。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="DAYU">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript" src="http://www.oschina.net/js/2012/jquery-1.7.1.min.js"></script>
</head>

<body>
<span id="id1" style="display:none;">2013-06-01 14:13:36</span>
<label id="showLeft">这里显示剩余时间</label>
<script>
            var     dt = $("#id1").text();
            var     strArr  = dt.split(" ");
            var     strDay  = strArr[0].split("-");
            var     strTime = strArr[1].split(":");
            //document.write(strDay[0]+strDay[1]+strDay[2]+strTime[0]+strTime[1]+strTime[2]);
            //这个函数是倒计时
            function getTime(){
                var minutes = 1000 * 60;
                 var hours   = minutes  * 60;
                 var days    = hours  * 24;
                //var years   = days * 365;
                 var date1   = new Date();
                 var date2   = new Date(Date.UTC(strDay[0], strDay[1]-1, strDay[2], strTime[0]-8, strTime[1], strTime[2]));
                 var minudt  = date2 - date1;
                //var y       = Math.floor(minudt/years);
                 var d       = Math.floor(minudt/days);
                 var h       = Math.floor((minudt - d * days)/hours);
                 var m       = Math.floor((minudt - d * days - h * hours)/minutes);
                 var s       = Math.floor((minudt - d * days - h * hours - m * minutes)/1000);
                document.getElementById("showLeft").innerHTML=d + "天" + h +  "时" + m + "分" + s + "秒";
            }
            getTime();
             setInterval(function(){
                 getTime();

            },1000)
</script>
</body>
</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="DAYU">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript" src="<a href="http://www.oschina.net/js/2012/jquery-1.7.1.min.js" rel="nofollow">http://www.oschina.net/js/2012/jquery-1.7.1.min.js</a>"></script>
</head>

<body>
<?php
//3天后的时间
$d =strtotime('+1 days');
$threeday=date('Y-m-d H:i:s',$d);
?>
<span id="id1" style="display:none;"><?=$threeday;?></span>
<label id="showLeft">这里显示剩余时间</label> 
<script>
    var     dt = $("#id1").text();
    var     strArr  = dt.split(" ");
    var     strDay  = strArr[0].split("-");
    var     strTime = strArr[1].split(":");
    //document.write(strDay[0]+strDay[1]+strDay[2]+strTime[0]+strTime[1]+strTime[2]);
    //这个函数是倒计时
    //function djs(){
    setInterval(function(){
         var minutes = 1000 * 60;
         var hours   = minutes  * 60;
         var days    = hours  * 24;
        //var years   = days * 365;                
         var date1   = new Date(); 
         var date2   = new Date(Date.UTC(strDay[0], strDay[1]-1, strDay[2], strTime[0]-8, strTime[1], strTime[2]));
         var minudt  = date2 - date1;
        //var y       = Math.floor(minudt/years);
         var d       = Math.floor(minudt/days); 
         var h       = Math.floor((minudt - d * days)/hours);
         var m       = Math.floor((minudt - d * days - h * hours)/minutes);
         var s       = Math.floor((minudt - d * days - h * hours - m * minutes)/1000);
        document.getElementById("showLeft").innerHTML=d + "天" + h +  "时" + m + "分" + s + "秒";
    },1000);
</script>    
</body>
</html>
--- 共有 11 条评论 ---
ahkxhyl回复 @MuBeiBei : 我取得是1天后的时间 5年前 回复
ahkxhyl回复 @MuBeiBei : 2013-06-01 14:13:36 5年前 回复
MuBeiBei回复 @ahkxhyl : 具体是什么?2013-5-31 14:21? 5年前 回复
ahkxhyl回复 @MuBeiBei : $d =strtotime('+1 days'); $threeday=date('Y-m-d H:i:s',$d); <span id="id1" style="display:none;"><?=$threeday;?></span> $("#id1").text();取得是$threeday的值 5年前 回复
ahkxhyl回复 @MuBeiBei : 嗯好的谢谢 5年前 回复

别忘了 替换一下你的php,我刚才测试用来的。

<?php
//3天后的时间
$d =strtotime('+1 days');
$threeday=date('Y-m-d H:i:s',$d);
?>
<span id="id1" style="display:none;"><?=$threeday;?></span>

--- 共有 2 条评论 ---
ahkxhyl每天开心! 5年前 回复
ahkxhyl非常感谢你啊 5年前 回复
顶部