开发者社区> 问答> 正文

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

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

展开
收起
kun坤 2020-06-14 09:23:05 457 0
0 条回答
写回答
取消 提交回答
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
RDS SQL Server CPU高使用率性能优化 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载