添加或修改cookie
function setCookie(id, value) { var dt = new Date(); var expireDay = 3600; //有效天数 dt.setTime(dt.getTime() + expireDay * 24 * 3600 * 1000); var cookie = id + '=' + escape(value); cookie += '; expires=' + dt.toGMTString(); document.cookie = cookie; }
获取cookie值
function getCookie(id) { var cookie = document.cookie; var arr = cookie.split(';'); for(var i=0; i<arr.length; i++) { var r = arr[i].split('='); if(r[0] == id)return r[1]; } return ''; }
删除cookie只需要将cookie的有效期设置,在现在之前的时间即可!就是让cookie过期就行!
欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]