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

倒计时

时间:2014-11-25 10:38:47      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   on   div   log   

/*倒计时
var countdown=(function(){
    return function(){
    var showTime = document.getElementById(this.id),
        beginNum=60,
        oril=showTime.innerHTML,
        string="%t%\u79d2\u540e\u53ef\u91cd\u65b0\u64cd\u4f5c",
        t;
    var showDown=function(){
        if(beginNum>0){
            beginNum-=1;
            showTime.innerHTML = string.replace("%t%",beginNum);
            showTime.disabled="disabled";
        }else{
            showTime.innerHTML =oril;
            clearInterval(t);
            showTime.disabled="";
        }
    };    
    t=setInterval(showDown,1000);
    };
})();
*/
(function($) {
  $.fn.countdown = function(options) {
    var opts = $.extend(true, {},
    $.fn.countdown.defaults, options);
    return this.each(function() {
        var $this = $(this);
        var t,beginNum=60,oril=$this.html(),
            string="%t%\u79d2\u540e\u53ef\u91cd\u65b0\u64cd\u4f5c";
        function countdown(){
                return function(e){
                    var origNum=beginNum;
                    $this.html(string.replace("%t%",beginNum));
                    $this.addClass("getCodeOff");
                    $this.attr("disabled",true);                    
                    var showDown=function(){
                        if(beginNum>0){
                            beginNum-=1;
                            $this.html(string.replace("%t%",beginNum));
                        }else{
                            beginNum=origNum;
                            $this.html(oril);
                            $this.removeClass("getCodeOff");
                            $this.attr("disabled",false);
                            clearInterval(t);
                        }
                    };    
                    t=window.setInterval(showDown,1000);
                };
            };
    $this.on("click",countdown());        
    });
  };
  $.fn.countdown.defaults = {
  };
})(jQuery);

 

倒计时

标签:style   blog   io   ar   color   sp   on   div   log   

原文地址:http://www.cnblogs.com/dingyuanxin/p/4120294.html

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