码迷,mamicode.com
首页 > 其他好文 > 详细

源生倒计时

时间:2015-01-11 20:21:35      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<style type="text/css">
*{margin: 0;padding: 0;list-style:none;outline: none;border: 0;}
div{width: 100px;height: 50px;line-height: 50px;text-align: center;background: orange;color: #fff;margin: 100px;cursor: pointer;}
</style>
</head>
<body>
    <div id="rTime">点击发送</div>
<script type="text/javascript">if (typeof(rTime)==undefined&&!rTime) var rTime={};
rTime={
    _$ : function(d){
        return document.getElementById(‘‘+d) || null;
    },

    sTime : function(g){
        if(typeof(g)==number&&g>0){
            this.g = g;
            this.t = g;
        }  
    },

    bind : function(b,d,e,fn){
        if(window.addEventListener){
            if(b){
                d.addEventListener(e,fn,false);
            }else{
                d.removeEventListener(e,fn,false);
            }
        }else{
            if(!b){
                d.attachEvent(on+e,fn);
            }else{
                d.detachEvent(on+e,fn);
            }
        }
    },

    dTime : function(t){
        var s = this, fn = function(){s.dTime(rTime);alert(1)};
        if(t!==undefined) var d = s._$(t);
        
        if(s.g!==undefined){
            if(s.g!==0){
                s.bind(false,d,click,fn)
                d.innerHTML = s.g+秒发送;
                window.setTimeout(function(){
                    s.g--;
                    s.innerHTML = s.g+秒发送;
                    s.dTime(rTime);
                }, 200)
            }else{
                s.g=s.t;
                d.innerHTML = 重新发送;
                s.bind(true,d,click,fn)
            }
        }
    }
}

rTime.sTime(1000);
rTime.dTime(rTime);

</script>
</body>
</html>

 

源生倒计时

标签:

原文地址:http://www.cnblogs.com/anson0415/p/4216999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!