首页 > 其他 > 详细

放刷新倒计时

时间:2014-09-26 12:44:19      阅读:279      评论:0      收藏:0      [点我收藏+]

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

 

放刷新倒计时

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!