1. 程式人生 > >javascript cookie 操作

javascript cookie 操作

bst 操作 time tco scrip code == date UNC

function getCookie(cname) {
let name = cname + "=";
let ca = document.cookie.split(‘;‘);
for (let i = 0; i < ca.length; i++) {
let c = ca[i].trim();
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}

function deleteCookie(cname) {
let d = new Date();
let expires = "expires=" + d.toGMTString();
document.cookie = cname + "=; " + expires;
}

function setCookie(cname, cvalue, exdays) {
let d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
let expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}

javascript cookie 操作