Cookie过期30天 [英] Cookie expiration 30 days
本文介绍了Cookie过期30天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,请你帮我把这个cookie设置为30天后过期而不是1.
Hi guys could you help me please to set this cookie to expire in 30 days in stead of 1.
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
推荐答案
如果
If
date.setTime(date.getTime()+(days*24*60*60*1000));
将到期时间设置为1天,那么这不是一个很好的飞跃
sets the expiry to 1 day hence, then it's not a great leap to work out that
date.setTime(date.getTime()+(days*30*24*60*60*1000));
会将其延长至30天
这篇关于Cookie过期30天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文