zoukankan      html  css  js  c++  java
  • dom

    我们做了在DIV里面显示年月日,时分秒

    首先要理清思路:

    • 定义一个变量接收时间
    • 分别显示年月日,时分秒
    • 用时重器,不停的去截取
    • 在div里面显示返回的时间

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"<head>

    <title></title>
    <script type="text/javascript">
    function show()
    {
    var num = new Date();         //定义一个变量来来接收返回的时间
    var str = num.getFullYear()+"年"+
    (num.getMonth()+1)+"月"
    +num.getDate()+"日"
    +num.getHours()&lt;10 ?"0"+num.getHours():num.getHours())
    +":"+num.getSeconds(+":"
    +(num.getMinutes() &lt;10 ?"0"+num.getMinutes():num.getMinutes())
    +":"+num.getSeconds()&lt;10 ?"0"+num.getSeconds():num.getSeconds());

    document.getElementsByTagName("div")[0].innerHTML= str;

    }
    setInterval("show()",1000);          //时重器,每1秒都不停的显示。


    </script>
    </head>
    <body>
    <div></div>
    </body>
    </html>


       首先要想到定义个变量来接收返回的时间,还要判断时分秒在<10的时候,我们要在前面给它加0,这样保证程序的逻辑更加清晰。

    孰能生巧吧,在只有理解了步骤以后,才能更加知道运行的逻辑顺序。

       我还是需要多练习,多总结。

  • 相关阅读:
    python爬虫基础(requests、BeautifulSoup)
    python中字典按键、值进行排序
    进程和线程的区别
    MySQL中的索引
    python中浅拷贝和深拷贝的区别
    谈谈final、finally、finalize的区别
    python中布尔值是false
    生成器的阐释
    文件处理
    内置函数
  • 原文地址:https://www.cnblogs.com/liner730/p/4508503.html
Copyright © 2011-2022 走看看