In the Web client, we often encounter reading or setting cookies, if the use of pure JS we may encounter some compatibility problems, here to introduce a more practical jquery operation Cookies Plug-ins
The source code for the plugin is as follows: code is as follows: Jquery.cookie = function (name, value, options) { if (typeof value!= ' undefined ') { options = Options | | {}; if (value = = null) { value = '; &NBS P options = $.extend ({}, Options); options.expires =-1; } var expires = '; if (Options.expires && (typeof options.expires = ' number ' | | options.expires.toUTCStr ing) { var date if (typeof OPTIONS.E Xpires = = ' number ') { date = new Date () &NBS P Date.settime (Date.gettime () + (Options.expires * 24 * 60 * 60 * 1000)); &NBsp else { date = Options.expires   ; } expires = '; Expires= ' + date.toutcstring (); } 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 { var cookievalue = null; if (document.cookie && document.cookie!= ') { var cookies = Document.cookie.split (';'); nbsp for (var i = 0; i < cookies.length i++) { &NBSp var cookie = Jquery.trim (Cookies[i]); if (cookie.substring (0, name.length + 1) = = (name + ' = ')) { Cookievalue = decodeuricomponent (cookie.substring name.len Gth + 1)); break; } } return cookievalue; }}; Specific use is as follows: 1, set the value of the cookie, such as we want to set variable name userid corresponding value of 123 cookies, the code is as follows: $.cookie (' userid ', ' 123 '); 2, create a new cookie, and set the duration of the cookie path domain name, and so on, the code is as follows: $.cookie (' userid, ' 123 ', {expires:7, path: '/', Domain: ' jquery.com ', Secure:tru e}); Note: If you remove the parameters for the following {}, the new will take effect with the default settings. 3, delete the cookie, that is, the corresponding cookie value to NULL, the code is as follows: $.cookie (' userid ', null); 4, read cookies, such as reading the variable name userid cookie value, the code is as follows: Var uid= $.cookie (' userid '); How about, using jquery to manipulate cookies is notVery simple, you do not have to write too many JS, also do not have to worry about those compatibility, everything is so smooth.