标签:
Fri, 31 Dec 9999 23:59:59 GMT
作为过期日。如果你不想使用这个日期,可使用世界末日Tue, 19 Jan 2038 03:14:07 GMT,
它是32位带符号整数能表示从1 January 1970 00:00:00 UTC开始的最大秒长(即01111111111111111111111111111111
, 是 new Date(0x7fffffff * 1e3)
).<script> //cookie function addCookie(objName,objValue,objDays){ var str = objName + "=" + escape(objValue); console.log(Infinity); //Infinity console.log(typeof Infinity); //number console.log(Infinity.constructor); //function Number() { [native code] } if(objDays > 0){ var date = new Date(); var ms = objDays*24*3600*1000; date.setTime(date.getTime() + ms); str += "; expires=" + date.toGMTString(); } if(objDays===Infinity){ str += "; expires=Fri, 31 Dec 9999 23:59:59 GMT"; } str += "; path=/"; document.cookie = str; }; var itemtitle=document.querySelector(".item-title"); document.querySelector(".sava_cookie").addEventListener("click",function(e){ var putCookieVal=itemtitle.innerHTML; addCookie(‘surface‘,putCookieVal,Infinity); }); </script>
https://developer.mozilla.org/zh-CN/docs/Web/API/Document/cookie
标签:
原文地址:http://www.cnblogs.com/surfaces/p/5548999.html