标签: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