1、设置cookie
function setCookie(name, value) {
var date = newDate();
var expiresDays = 1;
date.setTime(date.getTime() + expiresDays * 24 * 3600 * 1000);// cookie失效时间
document.cookie = name+'='+ escape(value) + ";expires=" + date.toGMTString() ;
}
2、删除cookie
function delCookie(name) {
var exp = newDate();
var expiresDays = 1;
exp.setTime(exp.getTime() - expiresDays * 24 * 60 * 60 * 1000);
var cval = getCookie(name);
if (cval != null) document.cookie = name +"="+ cval +"; expires="+ exp.toGMTString();
}
3、读取cookie
var getCookie = function (name) {
var arr;
var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
};