完美版cookie设置/得到/删除2016/423

function setCookie(key, value, t) {
	var oDate = new Date();
	oDate.setDate( oDate.getDate() + t );
	document.cookie = key + '=' + value + ';expires=' + oDate.toGMTString();
}
function getCookie(key)
{
	var arr1=document.cookie.split(';');
	for(var i=0;i<arr1.length;i++)
	{
		var arr2=arr1[i].split('=');
		if(key==arr2[0])
		{
			return decodeURI(arr2[1]);
		}
		 
	}
}

function removeCookie(key)
{
	setCookie(key,'',-1);
}
setCookie('name','huhu',10);

	alert(document.cookie)

  

posted on 2016-04-23 14:23  hduhdc  阅读(135)  评论(0编辑  收藏  举报