var myCookie =
{
isAllowed: document.cookie && document.cookie != '',
set: function(cn, cv, d, dm)
{
var now = new Date();
var expire = new Date();
if (d == null || d == 0)
{
d = 1;
}
expire.setTime(now.getTime() + 3600000 * 24 * d);
var cookieStr = cn + '=' + encodeURI(cv) + ';expires=' + expire.toGMTString() + ';domain=' + window.location.hostname + '; path=/';
alert(cookieStr);
document.cookie = cookieStr;
},
clear: function(cn, dm)
{
if (this.get(name))
{
document.cookie = cn + '=' + ((domain) ? '; domain=' + dm : '') + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
}
},
get: function(cn)
{
var dc = document.cookie;
var prefix = cn + '=';
var begin = dc.indexOf('; ' + prefix);
if (begin == -1)
{
begin = dc.indexOf(prefix);
if (begin != 0)
{
return null;
}
}
else
{
begin += 2;
}
var end = document.cookie.indexOf(';', begin);
if (end == -1)
{
end = dc.length;
}
return decodeURI(dc.substring(begin + prefix.length, end));
}
};
浏览器是不认识htp://localhost 这样常用的本地网址的,而必须写成htp://加127.0.0.1 呵呵。毕竟是特殊情况。写成locahost的话,cookie是写不进去的。经验之谈。。。