码迷,mamicode.com
首页 > Web开发 > 详细

JQuery $.cookie 应用

时间:2014-12-06 18:05:46      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   sp   on   div   log   

 1 if($.cookie(‘username‘)){
 2       alert(‘cookie exists‘);
 3       str = $.cookie(‘username‘);
 4       strs = str.split(‘&‘);
 5       $("input[name=‘username‘]").val(strs[0]);
 6       $("input[name=‘password‘]").val(strs[1]);
 7 }
 8 
 9  if($("#rememberme").is(":checked")){
10         $.cookie(‘username‘,$("input[name=‘username‘]").val() + "&" + $("input[name=‘password‘]").val(),{path:"/",expires:7});
11 }else{
12         $.cookie(‘username‘, null, { path: ‘/‘,expires: -1 });
13 }

 以上例子是用$.cookie来本地cookie,很久以前的插件了,慢慢学习中,跟大家分享一下

参数设置:
expires: (Number | Date)     

有效期,可以设置一个整数作为有效期(单位:天),也可以设置一个日期对象作为Cookie的过期日期。如果指定日期为负数,那么此cookie将被删除;如果不设置或者设置为null,那么此cookie将被当作Session Cookie处理,并且在浏览器关闭后删除

path:  (String)          Cookie的路径属性,默认是创建该cookie的页面路径

domain: (String)     Cookie的域名属性,默认是创建该cookie的页面域名

secure: (Boolean)  如果设为true,那么此cookie的传输会要求一个安全协议,例如HTTPS

//参数为引用,懒得写。例子自己手写。

 

JQuery $.cookie 应用

标签:style   blog   http   io   color   sp   on   div   log   

原文地址:http://www.cnblogs.com/zafuacm/p/4148440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!