javascript cookie 操作
Posted 寻坑者
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript cookie 操作相关的知识,希望对你有一定的参考价值。
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 操作的主要内容,如果未能解决你的问题,请参考以下文章
JavaScript:set-cookie 和响应处理原子操作吗?