js cookie


//存cookies
function SetCookie(name,value){
    var Days = 30; //30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
//取cookies
function getCookie(name)      {
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;
}
//删除cookie
function delCookie(name){

	var cookarr=document.cookie.toString().split(";");
	var date=new Date()
	var timeout=parseFloat(date.getTime())-(30*24*3600*1000);
	for (var i=0;i<cookarr.length;i++){
		var cookarrsub=cookarr[i].split("=");
		if (name == cookarrsub[0]){
			//document.cookie=cookarrsub[0]+"="+cookarrsub[1]+";expires="+timeout.toString();
			document.cookie=cookarrsub[0]+"=;expires="+timeout.toString();
		}
	}
}


你可能感兴趣的:(cookie)