【发布时间】:2021-09-28 20:56:01
【问题描述】:
function setcookie(cookieName, cookieValue, nDays) {
var today = new Date();
var expire = new Date();
if (nDays == null || nDays == 0) nDays = 1;
expire.setTime(today.getTime() + 3600000 * 24 * nDays); // changed that to * 14
document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
}
function readcookie(cookieName) {
var theCookie = " " + document.cookie;
var ind = theCookie.indexOf(" " + cookieName + "=");
if (ind == -1) ind = theCookie.indexOf(";" + cookieName + "=");
if (ind == -1 || cookieName == "") return "";
var ind1 = theCookie.indexOf(";", ind + 1);
if (ind1 == -1) ind1 = theCookie.length;
return unescape(theCookie.substring(ind + cookieName.length + 2, ind1));
}
我尝试将 nday 更改为 nday=14 但没有。
然后我尝试了expire.setTime(today.getTime() + 3600000 * 24 * 14),
还是什么都没有
我只需要使用此代码让 cookie 在设定的天数后过期。抱歉,我是本周刚开始接触 javascript 的新手。
【问题讨论】:
标签: javascript cookies