Javascript - Cookie

收藏着,网上有一些的写的很不靠谱。

function setCookie(name,value)
{
	// 30DAYS
	var Days = 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();
}
function getCookie(name)
{
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null) {
		return unescape(arr[2]);
	}
	return null;
}
function delCookie(name)
{
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null) document.cookie=name +"="+cval+";expires="+exp.toGMTString();
}

  

posted @ 2012-02-23 13:54  noevil  阅读(189)  评论(0编辑  收藏  举报