码迷,mamicode.com
首页 > 编程语言 > 详细

javascript cookie 操作

时间:2018-12-26 19:53:15      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:new   setcookie   indexof   script   cookie   tst   turn   substring   cname   

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 操作

标签:new   setcookie   indexof   script   cookie   tst   turn   substring   cname   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!