javaScript如何读取cookie
javaScript如何读取cookie,给个代码看看
------解决方案--------------------//寫COOKIE
function SetCookie(sName, sValue){
document.cookie = sName + "= " + escape(sValue) + "; ";
}
//讀COOKIE
function GetCookie(sName){
var aCookie = document.cookie.split( "; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split( "= ");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
}
function getCookies(name)
{
var arr = document.cookie.match(new RegExp( "(^| ) "+name+ "=([^;]*)(;|$) "));
if(arr != null) return unescape(arr[2]); return null;
}