zoukankan      html  css  js  c++  java
  • 一个小小的即时显示当前时间的jqurey控件

     效果:

    <div class="nowTime">
      <span></span>年 
      <span></span>月 
      <span></span>日
      <span></span>: 
      <span></span>: 
      <span></span>
    </div>
      
    <script>
     $(document).ready(function() {
                function time() {

              var date = new Date();
              var n = date.getFullYear();
              var y = date.getMonth() + 1;
              var t = date.getDate();
              var h = (date.getHours()<10)?"0"+date.getHours():date.getHours();
              var m = (date.getMinutes()<10)?"0"+date.getMinutes():date.getMinutes();
              var s = (date.getSeconds()<10)?"0"+date.getSeconds():date.getSeconds();

                    $('.nowTime span').eq(0).html(n);
                    $('.nowTime span').eq(1).html(y);
                    $('.nowTime span').eq(2).html(t);
                    $('.nowTime span').eq(3).html(h);
                    $('.nowTime span').eq(4).html(m);
                    $('.nowTime span').eq(5).html(s);
                    for (var i = 0; i < $('div').length; i++) {
                        if ($('div').eq(i).text().length == 1) {
                            $('div').eq(i).html(function(index, html) {
                                return 0 + html;
                            });
                        }
                    }
                }
                time();
                setInterval(time, 1000);
            });
    <script>
  • 相关阅读:
    Webpack配置
    闭包函数
    Vue2.0(一) 新手搭建环境
    用python编写一个合格的ftp程序,思路是怎样的?
    项目流程规范
    python: 基本数据类型 与 内置函数 知识整理
    前端知识 备忘录
    架构的演化路线
    深入理解并使用python的模块与包
    jquery 知识整理
  • 原文地址:https://www.cnblogs.com/BlackFungus/p/9109138.html
Copyright © 2011-2022 走看看