cookie

作者: 宇少_e010 | 来源:发表于2020-09-07 17:49 被阅读0次
//存储  名字 值 时间
function setCookie(name, value, Hours) {
  var d = new Date();
  var offset = 8;
  var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
  var nd = utc + (3600000 * offset);
  var exp = new Date(nd);
  exp.setTime(exp.getTime() + Hours * 60 * 60 * 1000);
  document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() 
  console.log(document.cookie)
}
//获取
function getCookie(name) {
  var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  if (arr != null) return unescape(arr[2]);
  return null
}

//   //删除cookie
function removeCookie(name) {
  document.cookie=encodeURIComponent(name)+"=;expires=" + new Date();
}

相关文章

网友评论

      本文标题:cookie

      本文链接:https://www.haomeiwen.com/subject/klylektx.html