zoukankan      html  css  js  c++  java
  • 封装倒计时 arguments妙用

        var cout = {
            init:function (classname) {
                var $this = this
                if (classname) {
                    var classname = classname
                }
                else {
                    var classname = ".bb"
                }
                $(document).delegate(classname, "click", function () {
                    var to_time = new Date(Date.parse($(this).text()))
                    $this.pri(this, to_time)
                })
            },
            last_time:function () {
                var $this = this
                var now = new Date();
                $this.long = $this.to_time.getTime() - now.getTime()
                $this.day = parseInt($this.long / (1000 * 60 * 60 * 24))
                $this.hours = parseInt($this.long % (1000 * 60 * 60 * 24) / (1000 * 60 * 60))
                $this.min = parseInt($this.long % (1000 * 60 * 60) / (1000 * 60))
                $this.sec = parseInt($this.long % (1000 * 60) / 1000)
                $this.text=$this.day + "天" + $this.hours + "小时" + $this.min + "分钟" + $this.sec + "秒"
    
            },
            pri:function (obj, time) {
                var $this = this
               function temp(){
                   $this.to_time = time
                   $this.last_time()
                   $(obj).html($this.text)
                   window.setTimeout(function () {
                      temp()
                   }, 1000)
               }
               temp()
            }
        }
    
        cout.init(".time")
    

    或者

     var cout = {
            init:function (classname) {
                var $this = this
                if (classname) {
                    var classname = classname
                }
                else {
                    var classname = ".bb"
                }
                $(document).delegate(classname, "click", function () {
                    var to_time = new Date(Date.parse($(this).text()))
                    $this.pri(this, to_time)()
                })
            },
            last_time:function () {
                var $this = this
                var now = new Date();
                $this.long = $this.to_time.getTime() - now.getTime()
                $this.day = parseInt($this.long / (1000 * 60 * 60 * 24))
                $this.hours = parseInt($this.long % (1000 * 60 * 60 * 24) / (1000 * 60 * 60))
                $this.min = parseInt($this.long % (1000 * 60 * 60) / (1000 * 60))
                $this.sec = parseInt($this.long % (1000 * 60) / 1000)
                $this.text = $this.day + "天" + $this.hours + "小时" + $this.min + "分钟" + $this.sec + "秒"
    
            },
            pri:function (obj, time) {
                var $this = this
                return function () {
                    $this.to_time = time
                    $this.last_time()
                    $(obj).html($this.text)
                    var temp = arguments.callee
                    window.setTimeout(function () {
                        temp()
                    }, 1000)
                }
            }
        }
    
        cout.init(".time")
    

    或者

       var cout = {
             init:function (classname) {
                 var $this = this
                 if (classname) {
                     var classname = classname
                 }
                 else {
                     var classname = ".bb"
                 }
                 $(document).delegate(classname, "click", function () {
                     var to_time = new Date(Date.parse($(this).text()))
                     $this.pri(this, to_time)
                 })
             },
             last_time:function (time) {
                 var $this = this
                 var now = new Date();
                 $this.long = time.getTime() - now.getTime()
                 $this.day = parseInt($this.long / (1000 * 60 * 60 * 24))
                 $this.hours = parseInt($this.long % (1000 * 60 * 60 * 24) / (1000 * 60 * 60))
                 $this.min = parseInt($this.long % (1000 * 60 * 60) / (1000 * 60))
                 $this.sec = parseInt($this.long % (1000 * 60) / 1000)
                 $this.text = $this.day + "天" + $this.hours + "小时" + $this.min + "分钟" + $this.sec + "秒"
     
             },
             pri:function (obj, time) {
                 var $this = this
                 return (function(time){
                     $this.last_time(time)
                     $(obj).html($this.text)
                     var temp = arguments.callee
                     window.setTimeout(function () {
                         temp(time)
                     }, 1000)
                 }(time))
             }
         }
     
         cout.init(".time")
     
    

      

     html

    <input value="2012/5/7 18:00" type="text">
     <input type="button" value="ok">
      <div >按照上面格式输入时间</div>
    

  • 相关阅读:
    如何添加mysql到环境变量
    SQLyog客户端无法连接MySQL服务器
    linux下插入的mysql数据乱码问题及第三方工具显示乱码问题
    mysql-5.7.10产生的日志时间与系统时间不一致
    linux—文件目录简单介绍
    python编程中的if __name__ == 'main' 的作用和原理
    Windows下Python版本的切换
    python—第三库的安装方法
    阿里云ubuntu16.04安装beef
    xss利用-beef攻击-演示
  • 原文地址:https://www.cnblogs.com/breakdown/p/2487609.html
Copyright © 2011-2022 走看看