4
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剛剛開始這個星期。
感謝。我會試試看。我能問,雖然怎麼來的,當我改變nDays = 14;它不起作用。我以爲它會做360000個* 24個* nDays這將有14 – Quinnystar27
刪除「如果(nDays == NULL || nDays == 0)」行,這將是確定 –