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

放刷新倒计时

时间:2014-09-26 13:53:08      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   art   cti   

项目中用到的,利用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))

 

放刷新倒计时

标签:style   blog   color   io   ar   sp   div   art   cti   

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

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