\n \u670d\u52a1\u5668\u4ee5 Cookie \u7684\u5f62\u5f0f\u5411\u7528\u6237\u7684\u6d4f\u89c8\u5668\u53d1\u9001\u4e00\u4e9b\u6570\u636e\u3002\u6d4f\u89c8\u5668\u53ef\u80fd\u4f1a\u63a5\u53d7 cookie\u3002\u5982\u679c\u63a5\u53d7\uff0c\u5219\u5c06\u5176\u4f5c\u4e3a\u7eaf\u6587\u672c\u8bb0\u5f55\u5b58\u50a8\u5728\u7528\u6237\u7684\u786c\u76d8\u9a71\u52a8\u5668\u4e0a\u3002\u73b0\u5728\uff0c\u5f53\u7528\u6237\u8bbf\u95ee\u540c\u4e00\u7f51\u7ad9\u7684\u53e6\u4e00\u4e2a\u9875\u9762\u65f6\uff0c\u6d4f\u89c8\u5668\u4f1a\u5c06\u76f8\u540c\u7684 cookie \u53d1\u9001\u5230\u670d\u52a1\u5668\u8fdb\u884c\u68c0\u7d22\u3002\u4e00\u65e6\u68c0\u7d22\u5230\uff0c\u76f8\u5e94\u7684\u670d\u52a1\u5668\u5c31\u4f1a\u8bb0\u4f4f\u4e4b\u524d\u5b58\u50a8\u7684\u5185\u5bb9\u3002\n <\/div>\n
\n Cookie \u662f\u5305\u542b\u4e94\u4e2a\u53ef\u53d8\u957f\u5ea6\u5b57\u6bb5\u7684\u7eaf\u6587\u672c\u6570\u636e\u8bb0\u5f55\n <\/div>\n
\u540d\u79f0\u548c\u503c: Cookie \u7684\u8bbe\u7f6e\u548c\u68c0\u7d22\u91c7\u7528\u952e\u503c<\/span>\u7684\u5f62\u5f0f
\n \u57df: \u5b83\u662f\u7f51\u7ad9\u7684\u57df\u540d\u3002<\/span>
\n \u8def\u5f84: \u5b83\u5305\u62ec\u8bbe\u7f6e cookie \u7684\u7f51\u9875\u6216\u76ee\u5f55\u3002\u5982\u679c\u60a8\u9700\u8981\u4ece\u4efb\u4f55\u9875\u9762\u6216\u76ee\u5f55\u68c0\u7d22 cookie\uff0c\u5b83\u53ef\u80fd\u4e3a\u7a7a\u3002\u5b83\u7684\u9ed8\u8ba4\u503c\u662f\u5f53\u524d\u9875\u9762\u7684\u8def\u5f84\u3002<\/span>
\n \u5b89\u5168: \u987e\u540d\u601d\u4e49\uff0ccookie \u53ef\u4ee5\u901a\u8fc7\u5b89\u5168\u670d\u52a1\u5668\u8fdb\u884c\u68c0\u7d22\u3002\u5982\u679c\u6b64\u5b57\u6bb5\u4e3a\u7a7a\uff0c\u5219\u4e0d\u9700\u8981\u6b64\u7c7b\u9650\u5236\u3002<\/span>
\n Expires: \u8fd9\u662f cookie \u7684\u5230\u671f\u65e5\u671f\u3002\u5982\u679c\u6b64\u5b57\u6bb5\u4e3a\u7a7a\uff0c\u5219 cookie \u5c06\u5728\u7528\u6237\u9000\u51fa\u6d4f\u89c8\u5668\u65f6\u8fc7\u671f\u3002<\/span> <\/p>\n\n \u6700\u521d\uff0ccookie \u662f\u4e3aCGI(\u901a\u7528\u7f51\u5173\u63a5\u53e3) \u7f16\u7a0b\u800c\u8bbe\u8ba1\u7684\u3002 cookie \u4e2d\u7684\u6570\u636e\u5728\u7f51\u7edc\u670d\u52a1\u5668\u548c\u7f51\u7edc\u6d4f\u89c8\u5668\u4e4b\u95f4\u81ea\u52a8\u4f20\u8f93\u3002\u56e0\u6b64\uff0c\u670d\u52a1\u5668\u4e0a\u7684 CGI \u811a\u672c\u53ef\u4ee5\u8bfb\u53d6\u548c\u5199\u5165\u5b58\u50a8\u5728\u5ba2\u6237\u7aef\u7684 cookie \u7684\u503c\u3002\n <\/div>\n
\n \u5728 JavaScript \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u6587\u6863\u5bf9\u8c61\u7684 cookie \u5c5e\u6027\u6765\u64cd\u4f5c cookie\u3002\u6211\u4eec\u8fd8\u53ef\u4ee5\u521b\u5efa\u3001\u8bfb\u53d6\u3001\u5220\u9664\u548c\u4fee\u6539\u9002\u7528\u4e8e\u5f53\u524d\u9875\u9762\u7684 cookie\u3002\n <\/div>\n
\u5b58\u50a8 Cookies<\/h2>\n\n \u521b\u5efa\u6216\u5b58\u50a8\u65b0 cookie \u7684\u6700\u7b80\u5355\u65b9\u6cd5\u662f\u5c06 name = value \u5b57\u7b26\u4e32\u503c\u5206\u914d\u7ed9 document.cookie \u5bf9\u8c61\u3002\u5b83\u770b\u8d77\u6765\u50cf\u8fd9\u6837:\n <\/div>\n
\n
\n\"document.cookie = \"<\/span>key1 = value1; key2 = value2; expires = date\";<\/pre>\n<\/code>\n <\/div>\n
\n \u4e0a\u8ff0\u8bed\u6cd5\u4e2d\u7684expire \u5c5e\u6027\u662f\u53ef\u9009\u7684\u3002\u5982\u679c\u6211\u4eec\u624b\u52a8\u4e3a\u8be5\u5c5e\u6027\u63d0\u4f9b\u6709\u6548\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff0c\u5219 cookie \u5c06\u5728\u7ed9\u5b9a\u7684\u65e5\u671f\u548c\u65f6\u95f4\u5230\u671f\u3002\n <\/div>\n
\n cookie \u7684\u503c\u4e0d\u80fd\u5305\u542b\u7a7a\u683c\u3001\u9017\u53f7\u6216\u5206\u53f7\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u5c06\u9700\u8981\u4f7f\u7528escape() \u51fd\u6570(JavaScript \u7684\u5185\u7f6e\u51fd\u6570 a>) \u7528\u4e8e\u5728\u5c06\u5305\u542b\u8fd9\u4e9b\u5b57\u7b26\u7684\u503c\u5b58\u50a8\u5230 cookie \u4e4b\u524d\u5bf9\u5176\u8fdb\u884c\u7f16\u7801\u3002\u540c\u6837\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u4f7f\u7528\u76f8\u5e94\u7684unescape() \u51fd\u6570\u6765\u8bfb\u53d6cookie\u503c\u3002\n <\/div>\n
\n
\ndocument.cookie = \"name=\"<\/span> + escape<\/span>(\"XYZ\"<\/span>);<\/pre>\n<\/code>\n <\/div>\n
\n \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4e0a\u8ff0cookie\u7684\u751f\u5b58\u671f\u662f\u5f53\u524d\u6d4f\u89c8\u5668\u4f1a\u8bdd\u3002\u8fd9\u610f\u5473\u7740\u5f53\u7528\u6237\u9000\u51fa\u6d4f\u89c8\u5668\u65f6\u5b83\u5c06\u4e22\u5931\u3002\n <\/div>\n
Cookies expire \u5c5e\u6027<\/h2>\n\n \u60a8\u53ef\u4ee5\u4f7f\u7528expires \u5c5e\u6027\u6307\u5b9acookie \u7684\u751f\u547d\u5468\u671f\u3002\u6b64\u5c5e\u6027\u63d0\u4f9b\u4e86\u4e00\u79cd\u521b\u5efa\u6301\u4e45\u6027 cookie \u7684\u65b9\u6cd5\u3002\u6b64\u5904\uff0c\u65f6\u95f4\u548c\u65e5\u671f\u7684\u58f0\u660e\u8868\u793a cookie \u7684\u6d3b\u52a8\u671f\u3002\u4e00\u65e6\u8d85\u8fc7\u58f0\u660e\u7684\u65f6\u95f4\uff0ccookie \u5c06\u81ea\u52a8\u5220\u9664\u3002\n <\/div>\n
\n \u4f8b\u5982:\n <\/div>\n
\n
\ndocument.cookie=\"username=XYZ;expires=Mon, 10 Aug 2040 12:00:00 UTC\"<\/span>; <\/pre>\n<\/code>\n <\/div>\n
Cookies max-age \u5c5e\u6027<\/h2>\n\n \u8981\u4f7fcookie\u5728\u5f53\u524d\u6d4f\u89c8\u5668\u7684\u4f1a\u8bdd\u4e4b\u5916\u6301\u7eed\u5b58\u5728\uff0c\u6211\u4eec\u9700\u8981\u6307\u5b9a\u5176\u751f\u547d\u5468\u671f(\u4ee5\u79d2\u4e3a\u5355\u4f4d)\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528 ma\u200b\u200bx-age \u5c5e\u6027\u6765\u6307\u5b9a\u5b83\u3002\u5b83\u662f expires \u5c5e\u6027\u7684\u66ff\u4ee3\uff0c\u5b83\u6307\u5b9a\u4ece\u5f53\u524d\u65f6\u523b\u5f00\u59cb\u4ee5\u79d2\u4e3a\u5355\u4f4d\u7684 cookie \u5230\u671f\u65f6\u95f4\u3002\u6b64\u5c5e\u6027\u786e\u5b9a cookie \u7684\u751f\u547d\u5468\u671f\uff0c\u5373\u5728\u5220\u9664\u4e4b\u524d\u5b83\u53ef\u4ee5\u5728\u7528\u6237\u7cfb\u7edf\u4e0a\u4fdd\u7559\u591a\u957f\u65f6\u95f4\u3002\n <\/div>\n
\n \u5982\u679c ma\u200b\u200bx-age \u5c5e\u6027\u7684\u503c\u662f \u96f6\u6216\u5426\u5b9a\uff0c\u5219\u5220\u9664cookie\u3002\n <\/div>\n
\n \u4f8b\u5982: \u4ee5\u4e0bcookie\u7684\u751f\u547d\u5468\u671f\u4e3a30\u5929\u3002\n <\/div>\n
\n
\ndocument.cookie=\"username=XYZ;max-age=\"<\/span> + <\/span>(60*60*24*30) + \";\"<\/span> <\/pre>\n<\/code>\n <\/div>\n
\u5b58\u50a8cookies\u793a\u4f8b<\/h3>\n\n \u8ba9\u6211\u4eec\u901a\u8fc7\u4ee5\u4e0b\u793a\u4f8b\u6765\u5c1d\u8bd5\u7406\u89e3\u8bbe\u7f6ecookie\u7684\u8bf4\u660e:\n <\/div>\n
\n
\n<html>\n<head> \n<title>Cookie Example<\/title>\n<\/head> \n<body style=\"text-align:center;\"<\/span>> \n <form name = \"myform\"<\/span> action = \" \"<\/span>>\n Enter Name: <input type=\"text\"<\/span> name=\"uname\"<\/span> >\n<input type=\"button\"<\/span> value=\"setCookie\"<\/span> onclick=\"setCookie()\"<\/span>> \n <\/form>\n <script> \n function setCookie() \n { \n if(document.myform.uname.value == \"\"<\/span>){\n alert(\"Required Name\"<\/span>);\n return; \n }\n value = escape(document.myform.uname.value) + \";\"<\/span>; \n document.cookie = \"name = \"<\/span><\/span> + value;\n document.write <\/span>(\"Cookie: \"<\/span> + \"name = \" + value); \n \n } \n \n <\/script> \n<\/body> \n<\/html><\/pre>\n<\/code>\n <\/div>\n
\n \u8f93\u51fa\n <\/div>\n
\n \u6210\u529f\u6267\u884c\u4ee5\u4e0a\u4ee3\u7801\u540e\uff0c\u4f1a\u5f97\u5230\u5982\u4e0b\u8f93\u51fa\u3002\n <\/div>\n
<\/p>\n
\n \u5982\u679c textfield \u4e3a\u7a7a\u5e76\u4e14\u60a8\u70b9\u51fb\u4e86 setCookie \u6309\u94ae\uff0c\u90a3\u4e48\u60a8\u5c06\u83b7\u5f97\u4e00\u4e2a\u8b66\u62a5\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002\n <\/div>\n
<\/p>\n
\n \u4e00\u65e6\u4f60\u8f93\u5165\u4e86\u6240\u9700\u7684\u503c\u5e76\u70b9\u51fbsetCookie \u6309\u94ae\uff0c\u7136\u540e\u60a8\u5c06\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\u3002\n <\/div>\n
<\/p>\n
\u8bfb\u53d6 Cookie<\/h2>\n\n \u8bfb\u53d6 cookie \u6bd4\u8bbe\u7f6e cookie \u7a0d\u5fae\u590d\u6742\u4e00\u4e9b\uff0c\u56e0\u4e3a document.cookie \u5c5e\u6027\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5305\u542b \u7a7a\u683c\u7684\u5b57\u7b26\u4e32 strong> \u548c \u5206\u53f7 \u5206\u9694\u7684\u6240\u6709 cookie \u5217\u8868\u3002\u60a8\u53ef\u4ee5\u5728\u9700\u8981\u8bbf\u95ee cookie \u7684\u5730\u65b9\u4f7f\u7528\u6b64\u5b57\u7b26\u4e32\u3002\n <\/div>\n
\n \u8981\u4ece\u5217\u8868\u4e2d\u83b7\u53d6 cookie\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u7684 split() \u51fd\u6570 \u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u952e\u548c\u503c\u7684\u5f62\u5f0f\u3002\n <\/div>\n
\u793a\u4f8b<\/h3>\n\n
\nfunction getCookie() {\nvar <\/span>cookievalue = document.cookie;\ndocument.write <\/span>(\"Cookies : \"<\/span> + cookievalue );\n}\n\/\/ get all the pairs of cookies in an array<\/span>\narr = cookievalue.split<\/span>(';'<\/span>);\n\/\/ take key-value pair out of this<\/span> array<\/span>\nfor(var <\/span>i = 0; i<arr.length; i++) \/\/ length is the array class <\/span>method which returns array length.<\/span>\n{ \nname = arr[i].split<\/span>('='<\/span><\/span>)[0];\nvalue = arr[i].split<\/span>('=')[1];\n}<\/pre>\n<\/code>\n <\/div>\n
\u66f4\u65b0 Cookies<\/h2>\n\n \u5728 JavaScript \u4e2d\uff0c\u60a8\u53ef\u4ee5\u50cf\u521b\u5efa cookie \u4e00\u6837\u901a\u8fc7\u7528\u65b0\u503c\u8986\u76d6\u5b83\u6765\u66f4\u6539 cookie\u3002\u66f4\u65b0\u6216\u4fee\u6539 cookie \u7684\u552f\u4e00\u65b9\u6cd5\u662f\u521b\u5efa\u53e6\u4e00\u4e2a cookie\u3002\u5982\u679c\u60a8\u521b\u5efa\u4e00\u4e2a\u4e0e\u73b0\u6709 cookie \u540d\u79f0\u76f8\u540c\u4f46\u8def\u5f84\u4e0d\u540c\u7684 cookie\uff0c\u5219\u4f1a\u5bfc\u81f4\u6dfb\u52a0\u4e00\u4e2a\u65b0 cookie\u3002\n <\/div>\n
\u793a\u4f8b<\/h3>\n\n
\n\/\/ Creating the cookie<\/span>\ndocument.cookie = \"name=XYZ;path=\/;max-age=\"<\/span> + 365*24*60*60;\n\/\/ Updating the cookie<\/span>\ndocument.cookie = \"name=ABC;path=\/;max-age=\"<\/span> + 30*24*60*60;<\/pre>\n<\/code>\n <\/div>\n
\u5220\u9664Cookie<\/h2>\n\n \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u60a8\u9700\u8981\u5220\u9664Cookie\u3002\u5220\u9664 cookie \u7684\u8fc7\u7a0b\u975e\u5e38\u7b80\u5355\u3002\u60a8\u4e0d\u9700\u8981\u6307\u5b9a cookie \u7684\u503c\u6765\u5220\u9664\u5b83\u3002\u4e3a\u6b64\uff0c\u60a8\u9700\u8981\u5c06 'expires' \u5c5e\u6027 \u7684\u503c\u8bbe\u7f6e\u4e3a\u4f20\u9012\u7684\u65e5\u671f\u3002\n <\/div>\n
\n \u60a8\u53ef\u4ee5\u5728\u4ee5\u4e0b\u4ee3\u7801\u4e2d\u770b\u5230\u76f8\u540c\u7684\u8bf4\u660e: > <\/p>\n
\n
\ndocument.cookie = \"name=value; expires= Thu, 21 Aug 2014 16:00:00 UTC; path=\/ \"<\/span><\/pre>\n<\/code>\n <\/div>\n<\/p><\/div>\n
<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"ES6 Cookieszh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[161],"tags":[],"class_list":["post-1927","post","type-post","status-publish","format-standard","hentry","category-es6jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1927"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1927"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1927\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}