cookie

2020-09-07  本文已影响0人  宇少_e010
//存储  名字 值 时间
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();
}

上一篇下一篇

猜你喜欢

热点阅读