Simple javascript operation cookie version
Copy codeThe Code is as follows:
Function setCookie (name, value, iDay ){
Var oDate = new Date ();
ODate. setDate (oDate. getDate () + iDay );
Document. cookie = name + '=' + value + '; expires =' + oDate;
}
Function getCookie (name ){
Var arr = document. cookie. split (';');
Var I = 0;
For (I = 0; I <arr. length; I ++ ){
Var arr2 = arr [I]. split ('= ');
If (arr2 [0] = name) {return arr2 [1];}
}
Return '';
}
Function removeCookie (name ){
SetCookie (name, '',-1 );
}
Cookie encapsulation version for javascript operations
Copy codeThe Code is as follows:
Var cookie = new function (){
This. set = function (name, value, hours ){
Var life = new Date (). getTime ();
Life + = hours * 1000*60;
Var cookieStr = name + "=" + escape (value) + "; expires =" + new Date (life). toGMTString ();
Document. cookie = cookieStr;
};
This. get = function (name ){
Var cookies = document. cookie. split (";");
If (cookies. length> 0 ){
Var cookie = cookies [0]. split ("= ");
If (cookie [0] = name) {return unescape (cookie [1]);}
}
Return null;
};
This. remove = function (name ){
Var cookieStr = name + "=" + escape ('null') + "; expires =" + new Date (). toGMTString ();
Document. cookie = cookieStr;
};
}
Keep the backup.