文章
2021/5/31
Js读写Cookie
2021-05-31
无标签
// 读取cookie  
function getCookie(key) {  
   if (document.cookie.length > 0) {  
      var start = document.cookie.indexOf(key + "=")  
      if (start !== -1) {  
         start = start + key.length + 1  
         var end = document.cookie.indexOf(";", start)  
         if (end === -1)  
            end = document.cookie.length  
         return unescape(document.cookie.substring(start, end))  
      }  
   }  
}  

// 设置cookie  
function setCookie(key, value, second) {  
   var cookie = key + "=" + escape(value) + ";";  
   if (second !== undefined && second !== '') {  
      cookie += "Max-Age=" + second + ";";  
   }  
   document.cookie = cookie  
}

如果咩咩的文章对您有帮助,您可以 请我喝牛奶