js操作cookies

js操作cookies的一些资源整理,希望对大家有所帮助!

<script language="javascript">

//写cookies函数
function SetCookie(name, value)//两个参数,一个是cookie的名子,一个是值
{
var Days = 10; //此 cookie 将被保存 10 天
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)//读取cookies函数
{
var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
if (arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

</script>

原文地址:http://www.cnblogs.com/xingyuan13/archive/2012/04/15/2448457.html

备注:escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串。


人生就像不能回头的旅途(网站) 广告位招商(网站) 人生就像不能回头的旅途(网店) 北京淘宝联盟(微博) 淘宝电器频道
原文地址:https://www.cnblogs.com/suizhikuo/p/2450602.html