更多可参考:
// 读 cookie 方法function getCookie(name){ var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); if(arr != null) return decodeURI(arr[2]); return null;}// 写 cookie 方法function setCookie(name,value,expiredays){ if(!isNaN(expiredays)){ var date = new Date(); date.setDate(date.getDate() + expiredays); //date.setTime(date.getTime() + expiredays * 24 * 3600 * 1000); document.cookie = name + '=' + encodeURI(value) + ';expires=' + date.toGMTString(); } else { document.cookie = name + '=' + encodeURI(value); }}alert(getCookie("name"));setCookie('name','游客');setCookie('name','普通用户',7);