# cookie 操作

设置cookie

function setCookie(name, value, domain, expriesDays, encode = false) {
  const Days = expriesDays || 10
  const exp = new Date()
  exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000)
  value = encode ? escape(value) : value
  document.cookie = `${name}=${value};domain=${domain};path=/;expires=${exp.toUTCString()}`
}

读取cookie

function getCookie(k) {
  const res = RegExp('(^|; )' + encodeURIComponent(k) + '=([^;]*)').exec(document.cookie)
  return res && res[2]
}
最后更新: Mon, 29 Jan 2024 14:20:15 GMT

0 评论

加载中...
访问量:-