设置cookie:
//time为过期后的毫秒数 function setCookie(name, value, time, path) { time = Number(time); if(!path) path = "/"; var exp = new Date(); exp.setTime(exp.getTime() + time); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=" + escape(path); }
获取cookie:
function getCookie(name) { var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return unescape(arr[2]); else return null; }
最新评论: