JS 操作 Cookie

 1     function setCookie(name, value, day) {
 2         var oDate = new Date();
 3         oDate.setDate(oDate.getDate() + day);
 4         document.cookie = name + "=" + value + ";expires=" + oDate;
 5     }
 6 
 7     function getCookie(name) {
 8         var arr = document.cookie.split('; ');
 9         for (var i = 0; i < arr.length; i++) {
10             var arr2 = arr[i].split('=');
11             if (arr2[0] === name) {
12                 return arr2[1];
13             }
14         }
15         return '';
16     }
17 
18     function removeCookie(name) {
19         setCookie(name, "1", -1);
20     }
原文地址:https://www.cnblogs.com/HuoAA/p/5074173.html