zoukankan      html  css  js  c++  java
  • 转 javascript 倒计时显示当年剩下的天时分秒

    <!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>一道JS面试题</title>
    <style>
    body
    {
     font-size
    :12px;
     font-family
    :"微软雅黑";
     line-height
    :1.8;
    }
    </style>
    </head>

    <body>
    <h3>一道JS大面试题</h3>
    <p>题目在网页里倒计时显示当年剩下的天时分秒,格式:XX年还剩下X天X时X分X秒</p>
    <div id="m1"></div>
    <script type="text/javascript">
    (
    function(){
     
    var day=hour=minitus=second=ms=0;
     
    var year=new Date().getFullYear()+1;
     
    var tmp=new Date(year,0,1)-new Date();
     day
    =Math.floor(tmp/86400000);
     (function(){
      tmp
    =(new Date(year,0,1)-new Date())%86400000;
      hour
    =Math.floor(tmp/3600000);
      tmp%=3600000;
      minitus
    =Math.floor(tmp/60000);
      tmp%=60000;
      second
    =Math.floor(tmp/1000);
      ms=tmp-1000*second;
      
      document.getElementById(
    "m1").innerHTML="距离"+year+"年还有 "+day+" 天 "+hour+" 小时 "+minitus+" 分 "+second+" 秒 "+ms;
      setTimeout(arguments.callee,
    50);
     })();
    })();
    </script>
    </body>
    </html>

  • 相关阅读:
    之前总结的,现在要找工作了,给大家分享一下
    numpy总结
    django知识分支_1
    Django小总结
    ORM
    百度在线编辑器 配置修改
    百度在线编辑器
    TP5 路由使用
    cache 订单队列
    绘制静态地图API-高德地图
  • 原文地址:https://www.cnblogs.com/zwei1121/p/1796378.html
Copyright © 2011-2022 走看看