由于页面刷新,如何保存客户端信息,想到了cookie
读cookie:
function GetCookie(sName)
{
// cookies are separated by semicolons
//var aCookie = document.cookie;
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 1;
}
{
// cookies are separated by semicolons
//var aCookie = document.cookie;
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 1;
}
设置cookie
function SetCookie(sValue)
{
var the_cookie = "switch=" + escape(sValue);
document.cookie = the_cookie;//写入Cookie
}
{
var the_cookie = "switch=" + escape(sValue);
document.cookie = the_cookie;//写入Cookie
}