简单封装cookie操作
1 1 //设置cookie 2 2 function setCookie(name, value, day) { 3 3 var oDate = new Date(); 4 4 oDate.setDate(oDate.getDate() + day); 5 5 document.cookie = name + '=' + value + ';expires=' + oDate; 6 6 } 7 7 //删除cookie 8 8 function delCookie(name) { 9 9 setCookie(name, 1, -1); 10 10 } 11 11 12 12 //获取cookie 13 13 function getCookie(name) { 14 14 var arr = document.cookie.split('; '); 15 15 for(var i = 0; i < arr.length; i++) { 16 16 var arrName = arr[i].split('='); 17 17 if(arrName[0] == name) { 18 18 return arrName[1]; 19 19 } 20 20 } 21 21 return ''; 22 22 }