<strong>Simple usage: </strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="95997" class="copybut" id="copybut95997" onclick="doCopy('code95997')"><u>Copy code </u></a></span> The code is as follows: </div> <div class="codebody" id="code95997"> <br>< html> <br><head> <br><title>JQuery-Cookie Plug-in</title> <br><script type="text/javascript" src="jquery-1.4.js">< ;/script> <br><script type="text/javascript" src="jquery.cookie.js"></script> <br></head> <br><body> <br><a href="#">Set cookie1</a><br> <br><a href="#">Set cookie2</a><br> <br><a href="#">Get cookie</a><br> <br><a href="#">Delete cookie</a><br> <br></body> <br></html> <br><script type="text/javascript"> <br>$(function(){ <br>var COOKIE_NAME = 'test_cookie'; <br>//Set cookie, pass time Interval<br>$('a').eq(0).click(function() { <br>$.cookie(COOKIE_NAME, 'test', { path: '/', expires: 1 }); <br>return false; <br>}); <br>// Set cookie, expiration time <br>$('a').eq(1).click(function() { <br>var date = new Date (); <br>date.setTime(date.getTime() (1 * 24 * 60 * 60 * 1000)); <br>$.cookie(COOKIE_NAME, 'test', { path: '/', expires: date }); <br>return false; <br>}); <br>// Get cookie <br>$('a').eq(2).click(function() { <br>alert($ .cookie(COOKIE_NAME)); <br>return false; <br>}); <br>// Delete cookie <br>$('a').eq(3).click(function() { <br> $.cookie(COOKIE_NAME, null, { path: '/' }); <br>return false; <br>}); <br>}); <br></script> <br> </div> <br><strong>The source code of the plug-in is also very simple: </strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="87711" class="copybut" id="copybut87711" onclick="doCopy('code87711')"><u>Copy the code</u></a></span> The code is as follows:</div> <div class="codebody" id="code87711"> <br>jQuery.cookie = function(name, value, options) { <br>if (typeof value != 'undefined') { // name and value given, set cookie <br>options = options || {} ; <br>if (value === null) { <br>value = ''; <br>options.expires = -1; <br>} <br>var expires = ''; <br>if (options .expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { <br>var date; <br>if (typeof options.expires == 'number') { <br>date = new Date(); <br>date.setTime(date.getTime() (options.expires * 24 * 60 * 60 * 1000)); <br>} else { <br>date = options.expires; <br> } <br>expires = '; expires=' date.toUTCString(); <br>} <br>var path = options.path ? '; path=' (options.path) : ''; <br>var domain = options.domain ? '; domain=' (options.domain) : ''; <br>var secure = options.secure ? '; secure' : ''; <br>document.cookie = [name, '=' , encodeURIComponent(value), expires, path, domain, secure].join(''); <br>} else { <br>var cookieValue = null; <br>if (document.cookie && document.cookie != ' ') { <br>var cookies = document.cookie.split(';'); <br>for (var i = 0; i < cookies.length; i ) { <br>var cookie = jQuery.trim( cookies[i]); <br>if (cookie.substring(0, name.length 1) == (name '=')) { <br>cookieValue = decodeURIComponent(cookie.substring(name.length 1)); <br>break; <br>} <br>} <br>} <br>return cookieValue; <br>} <br>}; <br> </div> <br><a href="http://plugins.jquery.com/project/cookie" target="_blank">cookie plugin</a> <br><br>You can also refer to: <br><a href="http://www.jb51.net/article/18276.htm" target="_blank">jquery cookie plug-in code class</a>