Use the getCookie, addCookie, and deleteCookie functions to obtain, add, and delete the client cache.
Copy to ClipboardReference content: [www.bkjia.com]/* get the cookie with the name specified in document. cookie
If the cookie is like a = 1; B = 2; c = 3; then getCookie ('A') returns 1
If it is like a = 1; B = x = 1 & y = 2; then getCookie ('B') returns the array ['X = 1', 'y = 2']; getCookie ('B', 'x') returns 1, getCookie ('B', 'y') returns 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;
},
// Add a cookie
AddCookie = function (name, value ){
Var cookieString = name + '=' + escape (value );
Document. cookie = cookieString;
},
// Delete a cookie
DeleteCookie = function (name ){
Document. cookie = name + '= 0 ;';
};