首页 > 代码库 > 放刷新倒计时

放刷新倒计时

项目中用到的,利用cookie记住防刷新

function getcookie(name) {var cookie_start = document.cookie.indexOf(name);var cookie_end = document.cookie.indexOf(";", cookie_start);return cookie_start == -1 ? ‘‘ : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));}function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {var expires = new Date();expires.setTime(expires.getTime() + seconds);document.cookie = escape(cookieName) + = + escape(cookieValue)+ (expires ? ; expires= + expires.toGMTString() : ‘‘)+ (path ? ; path= + path : /)+ (domain ? ; domain= + domain : ‘‘)+ (secure ? ; secure : ‘‘);}if (getcookie(deftime)==‘‘) setcookie(deftime,60,1000000);var deftime = getcookie(deftime);function time(obj){    if(deftime == 0){        obj.bind(click.myfn,function(){            //ajax如果成功执行time(obj)否则出错误提示            time(obj);        }).addClass(active).text(重新发送);        deftime = 60;    } else {        obj.unbind(.myfn).removeClass(active).text(deftime+秒后重发);          deftime--;        setcookie(deftime,deftime,1000000);        setTimeout(function(){time(obj)},1000)      }  }time($(.phone-time))

 

放刷新倒计时