jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE } var path = options.path ? '; path=' + options.path : ''; var domain = options.domain ? '; domain=' + options.domain : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { // only name given, get cookie var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } }; jQuery.fn.countDown = function(settings,to) { if(!to && to != settings.endNumber) { $.cookie('to',settings.startNumber); if($.cookie('to')){ to=$.cookie('to'); } else{ to = settings.startNumber; } } //alert(to) $.cookie('to',to); this.data("CR_currentTime",to); $(this).text(to).animate({"none":"none"},settings.duration,'',function() { if(to > settings.endNumber + 1) { $(this).countDown(settings,to - 1); }else{ $.cookie('to',null); settings.callBack(this); } }); return this; }; //计时&&重新计时 jQuery.fn.CRcountDown = function(settings) { settings = jQuery.extend({ startNumber: 10, endNumber: 0, duration: 1000, callBack: function() { } }, settings); this.data("CR_duration",settings.duration); this.data("CR_endNumber",settings.endNumber); this.data("CR_callBack",settings.callBack); return this.stop().countDown(settings); }; //计时暂停 jQuery.fn.pause = function(settings) { return this.stop(); }; //暂停后,重新开始 jQuery.fn.reStart = function() { return this.pause().CRcountDown({ startNumber : this.data("CR_currentTime"), duration : this.data("CR_duration"), endNumber : this.data("CR_endNumber"), callBack : this.data("CR_callBack") }); };