黑马程序员技术交流社区

标题: jq cookie操作 [打印本页]

作者: 997423686    时间: 2019-7-23 08:58
标题: jq cookie操作
本帖最后由 997423686 于 2019-7-27 08:45 编辑

jquery.cookie.js
下载:http://plugins.jquery.com/cookie/

$.cookie(‘the_cookie’, ‘the_value’); // 添加一个会话
$.cookie(‘the_cookie’, ‘the_value’, { expires: 7 }); //创建一个cookie并设置有效时间为 7天
var expiresDate= new Date();
expiresDate.setTime(expiresDate.getTime() + (120601000));//2h后过期
$.cookie(‘username’, res.data.username, { expires: expiresDate, path: ‘/’ });

$.cookie(‘the_cookie’, ‘the_value’, { expires: 7, path: ‘/’ }); //创建一个cookie并设置 cookie的有效路径
$.cookie(‘the_cookie’); //读取cookie
$.cookie(‘the_cookie’, null); //通过传递null作为cookie的值即可 //删除cookie
$.cookie(‘the_cookie’,‘the_value’,{
expires:7,
path:’/’,
domain:‘jquery.com’,
secure:true
})

expires:(Number|Date)有效期;设置一个整数时,单位是天;也可以设置一个日期对象作为Cookie的过期日期;
path:(String)创建该Cookie的页面路径;
domain:(String)创建该Cookie的页面域名;
secure:(Booblean)如果设为true,那么此Cookie的传输会要求一个安全协议,例如:HTTPS;

我的开源商城马上要发布 了,欢迎大家关注 开源地址:http://github.crmeb.net/u/lsq







欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2