jQuery操做cookie的插件,大概的使用方法以下
$.cookie('the_cookie'); //读取Cookie值
$.cookie('the_cookie', 'the_value'); //设置cookie的值
$.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true});//新建一个cookie 包括有效期 路径 域名等
$.cookie('the_cookie', null); //删除一个cookie
设置一个名称为blog,值为css9.net的cookie:
$.cookie("blog", "css9.net");
设置一个名称为blog,值为css9.net的cookie,同时设置过时时间(expires属性)为7天:
$.cookie("blog", "css9.net", { expires: 7 });
设置一个名称为blog,值为css9.net的cookie,设置过时时间(expires属性)为7天,同时设置cookie的path属性为”/admin”
$.cookie("blog", "css9.net", { path: '/admin', expires: 7 });
设置一个名称为blog,值为css9.net的cookie,设置过时时间(expires属性)为7天,同时设置cookie的path属性为”location.pathname”,
$.cookie("blog", "css9.net", {hostexpires: 7, path:location.pathname,domain:location }); css
读取名称为blog的cookie值:
alert( $.cookie("blog") );
删除cookie:
$.cookie("example", null);