首页 > 编程语言 > 详细

javascript cookie 操作

时间:2018-12-26 19:04:10      阅读:184      评论:0      收藏:0      [点我收藏+]
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 操作

原文:https://www.cnblogs.com/dannyyao/p/10180794.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!