1.设置cookie
function setCookie(name,value,days){ if(days){ var date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); var expires = ';expires='+date.toGMTString(); }else{ var expires = ''; } document.cookie = name + '=' + value + expires + ';path=/';}实例: setCookie('user_id','10086',30); 30表示此cookie保存30天。
2.读取cookie
function getCookie(name){ var strCookie=document.cookie; var arrCookie=strCookie.split("; "); for(var i=0;i
实例: getCookie('user_id'); 结果为字符串10086
3.删除cookie
function delCookie(name){ setCookie(name,'',-1); }
实例: delCookie('user_id');