<\/span><\/h3>\n\n\n\n<script src=\"scripts\/jquery-1.6.4.js\" type=\"text\/javascript\"><\/script> \n<script src=\"scripts\/jquery.cookie.js\" type=\"text\/javascript\"><\/script><\/pre>\n\n\n\n<\/span>\u4f7f\u7528\u65b9\u6cd5<\/span><\/h3>\n\n\n\n<\/span>\u65b0\u6dfb\u52a0\u4e00\u4e2a\u4f1a\u8bdd cookie<\/span><\/h4>\n\n\n\n$.cookie('the_cookie', 'the_value');<\/code><\/pre>\n\n\n\n\u6ce8\uff1a\u5f53\u6ca1\u6709\u6307\u660e cookie\u6709\u6548\u65f6\u95f4\u65f6\uff0c\u6240\u521b\u5efa\u7684cookie\u6709\u6548\u671f\u9ed8\u8ba4\u5230\u7528\u6237\u5173\u95ed\u6d4f\u89c8\u5668\u4e3a\u6b62\uff0c\u6240\u4ee5\u88ab\u79f0\u4e3a<\/p>\n\n\n\n
\u201c\u4f1a\u8bddcookie\uff08session cookie\uff09\u201d\u3002<\/p>\n\n\n\n
<\/span>\u521b\u5efa\u4e00\u4e2acookie\u5e76\u8bbe\u7f6e\u6709\u6548\u65f6\u95f4\u4e3a 7\u5929:<\/span><\/h4>\n\n\n\n$.cookie('the_cookie', 'the_value', { expires: 7 });<\/code><\/pre>\n\n\n\n\u6ce8\uff1a\u5f53\u6307\u660e\u4e86cookie\u6709\u6548\u65f6\u95f4\u65f6\uff0c\u6240\u521b\u5efa\u7684cookie\u88ab\u79f0\u4e3a\u201c\u6301\u4e45 cookie \uff08persistent cookie\uff09\u201d\u3002 <\/p>\n\n\n\n
<\/span>\u521b\u5efa\u4e00\u4e2acookie\u5e76\u8bbe\u7f6e cookie\u7684\u6709\u6548\u8def\u5f84\uff1a<\/span><\/h4>\n\n\n\n$.cookie('the_cookie', 'the_value', { expires: 7, path: '\/' });<\/code><\/pre>\n\n\n\n\u6ce8\uff1a\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u8bbe\u7f6e cookie\u7684\u7f51\u9875\u624d\u80fd\u8bfb\u53d6\u8be5 cookie\u3002\u5982\u679c\u60f3\u8ba9\u4e00\u4e2a\u9875\u9762\u8bfb\u53d6\u53e6\u4e00\u4e2a\u9875\u9762\u8bbe\u7f6e\u7684cookie\uff0c\u5fc5\u987b\u8bbe\u7f6ecookie\u7684\u8def\u5f84\u3002cookie\u7684\u8def\u5f84\u7528\u4e8e\u8bbe\u7f6e\u80fd\u591f\u8bfb\u53d6 cookie\u7684\u9876\u7ea7\u76ee\u5f55\u3002\u5c06\u8fd9\u4e2a\u8def\u5f84\u8bbe\u7f6e\u4e3a\u7f51\u7ad9\u7684\u6839\u76ee\u5f55\uff0c\u53ef\u4ee5\u8ba9\u6240\u6709\u7f51\u9875\u90fd\u80fd\u4e92\u76f8\u8bfb\u53d6 cookie \uff08\u4e00\u822c\u4e0d\u8981\u8fd9\u6837\u8bbe\u7f6e\uff0c\u9632\u6b62\u51fa\u73b0\u51b2\u7a81\uff09 \u3002\u00a0<\/p>\n\n\n\n
<\/span>\u8bfb\u53d6cookie\uff1a<\/span><\/h4>\n\n\n\n$.cookie('the_cookie'); \/\/ cookie\u5b58\u5728 => 'the_value'\n$.cookie('not_existing'); \/\/ cookie\u4e0d\u5b58\u5728 => null<\/code><\/pre>\n\n\n\n<\/span>\u5220\u9664cookie\uff0c\u901a\u8fc7\u4f20\u9012null\u4f5c\u4e3acookie\u7684\u503c\u5373\u53ef\uff1a<\/span><\/h4>\n\n\n\n$.cookie('the_cookie', null);<\/code><\/pre>\n\n\n\n<\/span>\u5c06cookie\u5199\u5165\u6587\u4ef6<\/span><\/h4>\n\n\n\nvar COOKIE_NAME = 'username'; \n if( $.cookie(COOKIE_NAME) ){ \n $(\"#username\").val( $.cookie(COOKIE_NAME) ); \n } \n $(\"#check\").click(function(){ \n if(this.checked){ \n $.cookie(COOKIE_NAME, $(\"#username\").val() , { path: '\/', expires: 10, domain: 'jquery.com', secure: true }); \n \/\/var date = new Date(); \n \/\/date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000)); \/\/\u4e09\u5929\u540e\u7684\u8fd9\u4e2a\u65f6\u5019\u8fc7\u671f \n \/\/$.cookie(COOKIE_NAME, $(\"#username\").val(), { path: '\/', expires: date }); \n }else{ \n $.cookie(COOKIE_NAME, null, { path: '\/' }); \/\/\u5220\u9664cookie \n } \n });<\/code><\/pre>\n\n\n\n<\/span>\u53c2\u6570\u8bbe\u7f6e<\/span><\/h3>\n\n\n\nexpires: (Number | Date)\u00a0<\/strong>\u00a0\u00a0\u00a0\u00a0 \u6709\u6548\u671f\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u6574\u6570\u4f5c\u4e3a\u6709\u6548\u671f\uff08\u5355\u4f4d\uff1a\u5929\uff09\uff0c\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u65e5\u671f\u5bf9\u8c61\u4f5c\u4e3aCookie\u7684\u8fc7\u671f\u65e5\u671f\u3002\u5982\u679c\u6307\u5b9a\u65e5\u671f\u4e3a\u8d1f\u6570\uff0c\u90a3\u4e48\u6b64cookie\u5c06\u88ab\u5220\u9664\uff1b\u5982\u679c\u4e0d\u8bbe\u7f6e\u6216\u8005\u8bbe\u7f6e\u4e3anull\uff0c\u90a3\u4e48\u6b64cookie\u5c06\u88ab\u5f53\u4f5cSession Cookie\u5904\u7406\uff0c\u5e76\u4e14\u5728\u6d4f\u89c8\u5668\u5173\u95ed\u540e\u5220\u9664<\/p>\n\n\n\npath:\u00a0 (String)\u00a0<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Cookie\u7684\u8def\u5f84\u5c5e\u6027\uff0c\u9ed8\u8ba4\u662f\u521b\u5efa\u8be5cookie\u7684\u9875\u9762\u8def\u5f84<\/p>\n\n\n\ndomain: (String)<\/strong>\u00a0\u00a0\u00a0\u00a0 Cookie\u7684\u57df\u540d\u5c5e\u6027\uff0c\u9ed8\u8ba4\u662f\u521b\u5efa\u8be5cookie\u7684\u9875\u9762\u57df\u540d<\/p>\n\n\n\nsecure: (Boolean)\u00a0<\/strong> \u5982\u679c\u8bbe\u4e3atrue\uff0c\u90a3\u4e48\u6b64cookie\u7684\u4f20\u8f93\u4f1a\u8981\u6c42\u4e00\u4e2a\u5b89\u5168\u534f\u8bae\uff0c\u4f8b\u5982HTTPS<\/p>\n\n\n\n<\/span>jquery.cookie.js<\/span><\/h2>\n\n\n\n\/**\n * Cookie plugin\n *\n * Copyright (c) 2006 Klaus Hartl (stilbuero.de)\n * Dual licensed under the MIT and GPL licenses:\n * http:\/\/www.opensource.org\/licenses\/mit-license.php\n * http:\/\/www.gnu.org\/licenses\/gpl.html\n *\n *\/\n\n\/**\n * Create a cookie with the given name and value and other optional parameters.\n *\n * @example $.cookie('the_cookie', 'the_value');\n * @desc Set the value of a cookie.\n * @example $.cookie('the_cookie', 'the_value', {expires: 7, path: '\/', domain: 'jquery.com', secure: true});\n * @desc Create a cookie with all available options.\n * @example $.cookie('the_cookie', 'the_value');\n * @desc Create a session cookie.\n * @example $.cookie('the_cookie', null);\n * @desc Delete a cookie by passing null as value.\n *\n * @param String name The name of the cookie.\n * @param String value The value of the cookie.\n * @param Object options An object literal containing key\/value pairs to provide optional cookie attributes.\n * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.\n * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.\n * If set to null or omitted, the cookie will be a session cookie and will not be retained\n * when the the browser exits.\n * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).\n * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).\n * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will\n * require a secure protocol (like HTTPS).\n * @type undefined\n *\n * @name $.cookie\n * @cat Plugins\/Cookie\n * @author Klaus Hartl\/klaus.hartl@stilbuero.de\n *\/\n\n\/**\n * Get the value of a cookie with the given name.\n *\n * @example $.cookie('the_cookie');\n * @desc Get the value of a cookie.\n *\n * @param String name The name of the cookie.\n * @return The value of the cookie.\n * @type String\n *\n * @name $.cookie\n * @cat Plugins\/Cookie\n * @author Klaus Hartl\/klaus.hartl@stilbuero.de\n *\/\njQuery.cookie = function(name, value, options) {\n if (typeof value != 'undefined') { \/\/ name and value given, set cookie\n options = options || {};\n if (value === null) {\n value = '';\n options.expires = -1;\n }\n var expires = '';\n if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {\n var date;\n if (typeof options.expires == 'number') {\n date = new Date();\n date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));\n } else {\n date = options.expires;\n }\n expires = '; expires=' + date.toUTCString(); \/\/ use expires attribute, max-age is not supported by IE\n }\n var path = options.path ? '; path=' + options.path : '';\n var domain = options.domain ? '; domain=' + options.domain : '';\n var secure = options.secure ? '; secure' : '';\n document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');\n } else { \/\/ only name given, get cookie\n var cookieValue = null;\n if (document.cookie && document.cookie != '') {\n var cookies = document.cookie.split(';');\n for (var i = 0; i < cookies.length; i++) {\n var cookie = jQuery.trim(cookies[i]);\n \/\/ Does this cookie string begin with the name we want?\n if (cookie.substring(0, name.length + 1) == (name + '=')) {\n cookieValue = decodeURIComponent(cookie.substring(name.length + 1));\n break;\n }\n }\n }\n return cookieValue;\n }\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Cookie\u662f\u7f51\u7ad9\u8bbe\u8ba1\u8005\u653e\u7f6e\u5728\u5ba2\u6237\u7aef\u7684\u5c0f\u6587\u672c\u6587\u4ef6\u3002Cookie\u80fd\u4e3a\u7528\u6237\u63d0\u4f9b\u5f88\u591a\u7684\u4f7f\u5f97\uff0c\u4f8b\u5982\u8d2d\u7269\u7f51\u7ad9\u5b58\u50a8\u7528\u6237\u66fe\u7ecf […]<\/p>\n","protected":false},"author":1,"featured_media":43073,"comment_status":"open","ping_status":"closed","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[46,45,47,48],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/46573"}],"collection":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/comments?post=46573"}],"version-history":[{"count":0,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/46573\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media\/43073"}],"wp:attachment":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media?parent=46573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/categories?post=46573"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/tags?post=46573"}],"curies":[{"name":"wp","href":"http:\/\/api.w.org\/{rel}","templated":true}]}}