Example $. Cookie ('name', 'value ');
Set the cookie value and set the value of the name variable to value.
Example $. Cookie ('name', 'value', {expires: 7, path: '/', domain: 'jquery. com', secure: true });
Create a cookie including the Domain Name of the validity period
Example $. Cookie ('name', 'value ');
Create cookie
Example $. Cookie ('name', null );
Delete a cookie
VaR account = $. Cookie ('name ');
Get a cookie (name) value to myvar
Code As follows: Copy code The Code is as follows: jquery. Cookie = function (name, value, options ){
If (typeof value! = 'Undefined') {// name and value given, set cookie
Options = options | {};
If (value = NULL ){
Value = '';
Options. expires =-1;
}
VaR expires = '';
If (options. expires & (typeof options. expires = 'number' | options. expires. toutcstring )){
VaR date;
If (typeof options. expires = 'number '){
Date = new date ();
Date. settime (date. gettime () + (options. expires * 24x60*60*1000 ));
} Else {
Date = options. expires;
}
Expires = '; expires =' + date. toutcstring (); // use expires attribute, Max-age is not supported by IE
}
VaR Path = options. Path? '; Path =' + options. Path :'';
VaR domain = options. domain? '; Domain =' + options. Domain :'';
VaR secure = options. secure? '; Secure ':'';
Document. Cookie = [name, '=', encodeuricomponent (value), expires, path, domain, secure]. Join ('');
} Else {// only name given, get Cookie
VaR cookievalue = NULL;
If (document. Cookie & document. Cookie! = ''){
VaR cookies = Document. Cookie. Split (';');
For (VAR I = 0; I <cookies. length; I ++ ){
VaR cookie = jquery. Trim (Cookies [I]);
// Does this cookie string begin with the name we want?
If (cookie. substring (0, name. Length + 1) = (name + '= ')){
Cookievalue = decodeuricomponent (cookie. substring (name. Length + 1 ));
Break;
}
}
}
Return cookievalue;
}
};
then I checked discuz! The Operation Method for Cookie
is as follows, and a traversal is missing. Processing of split arrays copy Code the code is as follows: function getcookie (name) {
var cookie_start = document. cookie. indexof (name);
var cookie_end = document. cookie. indexof (";", cookie_start);
return cookie_start =-1? '': Unescape (document. Cookie. substring (cookie_start + name. Length + 1, (cookie_end> cookie_start? Cookie_end: document. cookie. length);
}< br> function setcookie (cookiename, cookievalue, seconds, path, domain, secure) {
var expires = new date ();
expires. settime (expires. gettime () + seconds);
document. cookie = escape (cookiename) + '=' + escape (cookievalue)
+ (expires? '; Expires =' + expires. togmtstring (): '')
+ (path? '; Path =' + path: '/')
+ (domain? '; Domain =' + domain: '')
+ (secure? '; Secure': '');
}