倒计时这样写会飙高CPU怎么回事,哪里写错了

发布于 2021-11-15 22:41:07 字数 2475 浏览 734 评论 11

<!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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

天涯离梦残月幽梦 2021-11-21 03:40:41

非常感谢你啊

毁梦 2021-11-21 03:40:34

每天开心!

彩扇题诗 2021-11-21 03:39:56

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

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

终陌 2021-11-21 03:36:06

区分setTimeout和setInterval就好办了

路还长,别太狂 2021-11-21 03:29:54

回复
嗯好的谢谢

叹沉浮 2021-11-21 02:06:01

回复
$d =strtotime('+1 days'); $threeday=date('Y-m-d H:i:s',$d); <span id="id1" style="display:none;"><?=$threeday;?></span> $("#id1").text();取得是$threeday的值

少女净妖师 2021-11-21 01:35:53

回复
具体是什么?2013-5-31 14:21?

深巷少女 2021-11-20 23:12:49

回复
2013-06-01 14:13:36

混吃等死 2021-11-20 22:43:28

回复
我取得是1天后的时间

天涯离梦残月幽梦 2021-11-20 19:11:44
<!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>
长安忆 2021-11-16 14:08:37

用这个就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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文