Cookie 的作用就是用于解决 “如何记录客户端的用户信息”:
Cookie 以名/值对形式存储,如下所示:
username=John Doe
1.创建
document.cookie=“username=John Doe”;
<1>您还可以为 cookie 添加一个过期时间(以 UTC 或 GMT 时间)。默认情况下,cookie 在浏览器关闭时删除:
document.cookie=“username=John Doe; expires=Thu, 18 Dec 2043 12:00:00 GMT”;
<2>您可以使用 path 参数告诉浏览器 cookie 的路径。默认情况下,cookie 属于当前页面。
document.cookie=“username=John Doe; expires=Thu, 18 Dec 2043 12:00:00 GMT; path=/”;
function setCookie(ckey,cval,exdays)
{
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTStr