这边,这边,总结一下原生JS中有关于cookie函数的封装呀~~~
(一)设置cookie
function setCookie(key,val,expires){ var d = new Date(); d.setDate(d.getDate()+expires); document.cookie = key+"="+val+";path=/;expires="+d; }
(二)删除Cookie
function removeCookie(key,val){ setCookie(key,val,-1) }
(三)查看cookie
function getCookie(key){ var cookie = document.cookie; var arr = cookie.split("; "); for(var i=0;i<arr.length;i++){ var newArr = arr[i].split("="); if(key == newArr[0]){ return newArr[1]; } } }