用getCookie,addCookie,deleteCookie三个小函数来对客户端缓存进行获取、添加、删除的操作

 /*获取document.cookie中指定名字的cookie
若cookie形如:a=1;b=2;c=3;那么getCookie('a')返回1
若形如a=1;b=x=1&y=2;那么getCookie('b')返回数组['x=1','y=2'];getCookie('b','x')返回1,getCookie('b','y')返回2
*/
var getCookie=function(name,name2){
    var strCookie=document.cookie,arrCookie=strCookie.split(';'),i=arrCookie.length,arr,i2,TmpStr;
    while(i--){
        TmpStr=(arr=arrCookie[i]).split('=');
        if(TmpStr[0].replace(' ','')==name){
            if((i2=TmpStr.length)==2){
                return TmpStr[1];
            }else{
                TmpStr.shift();
                TmpStr=TmpStr.join('=').split('&');
                if(name2==undefined){
                    return TmpStr;
                }else{
                    i2=TmpStr.length;
                    while(i2--){
                        if((arr=TmpStr[i2].split('='))[0].replace(' ','')==name2)return(arr[1]);
                    }
                }
            }
        }
    }
    return 0;
},

//添加一个cookie
addCookie=function(name,value){
    var cookieString=name+'='+escape(value);
    document.cookie=cookieString;
},

//删除一个cookie
deleteCookie=function(name){
    document.cookie=name+'=0;';
};