码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-04-23 14:43:29      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:

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)

  

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

标签:

原文地址:http://www.cnblogs.com/hduhdc/p/5424570.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!