1. 写cookie
var exdate = new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie = key + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
}
2.读cookie
function getCookie(key) {
var str = document.cookie;
var reg = new RegExp('(^| )' + key + '=([^;]*)($|;)');//*重复零次或更多次
var v = str.match(reg);
return v&&v[2];
}
3.删除cookie
function delCookie(key){
var value = getCookie(key);
if(value!=null) {
var exp = new Date();
document.cookie = key + "=" + value + ";expires=" + exp.toGMTString();
}
}