菜鸟求用JS写,删Cookies
生成个Cookies,记录访问过我的网站
还有用JS删除某个Cookies
菜鸟 怎么做
------解决方案--------------------
常用的3个方法
function SetCookie(sName, sValue)
{
document.cookie = sName + "=" + escape(sValue);
var date = new Date();
date.setMonth(date.getMonth()+1);
document.cookie += ("; expires=" + date.toUTCString());
}
function GetCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
// a cookie with the requested name does not exist
return null;
}
function DelCookie(sName)
{
document.cookie = sName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}