jQuery插件 -- Cookie插件jquery.cookie.js
2012-07-06 14:38
267 查看
Cookie是网站设计者放置在客户端的小文本文件。Cookie能为用户提供很多的使得,例如购物网站存储用户曾经浏览过的产品列表,或者门户网站记住用户喜欢选择浏览哪类新闻。 在用户允许的情况下,还可以存储用户的登录信息,使得用户在访问网站时不必每次都键入这些信息
Cookie下载地址: http://plugins.jquery.com/project/cookie
使用方法:
1.引入jquery.cookie.js
expires: (Number | Date) 有效期,可以设置一个整数作为有效期(单位:天),也可以设置一个日期对象作为Cookie的过期日期。如果指定日期为负数,那么此cookie将被删除;如果不设置或者设置为null,那么此cookie将被当作Session Cookie处理,并且在浏览器关闭后删除
path: (String) Cookie的路径属性,默认是创建该cookie的页面路径
domain: (String) Cookie的域名属性,默认是创建该cookie的页面域名
secure: (Boolean) 如果设为true,那么此cookie的传输会要求一个安全协议,例如HTTPS
Cookie下载地址: http://plugins.jquery.com/project/cookie
使用方法:
1.引入jquery.cookie.js
<script src="scripts/jquery-1.6.4.js" type="text/javascript"></script> <script src="scripts/jquery.cookie.js" type="text/javascript"></script>2.将cookie写入文件
var COOKIE_NAME = 'username'; if( $.cookie(COOKIE_NAME) ){ $("#username").val( $.cookie(COOKIE_NAME) ); } $("#check").click(function(){ if(this.checked){ $.cookie(COOKIE_NAME, $("#username").val() , { path: '/', expires: 10 }); //var date = new Date(); //date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000)); //三天后的这个时候过期 //$.cookie(COOKIE_NAME, $("#username").val(), { path: '/', expires: date }); }else{ $.cookie(COOKIE_NAME, null, { path: '/' }); //删除cookie } });参数设置:
expires: (Number | Date) 有效期,可以设置一个整数作为有效期(单位:天),也可以设置一个日期对象作为Cookie的过期日期。如果指定日期为负数,那么此cookie将被删除;如果不设置或者设置为null,那么此cookie将被当作Session Cookie处理,并且在浏览器关闭后删除
path: (String) Cookie的路径属性,默认是创建该cookie的页面路径
domain: (String) Cookie的域名属性,默认是创建该cookie的页面域名
secure: (Boolean) 如果设为true,那么此cookie的传输会要求一个安全协议,例如HTTPS
相关文章推荐
- jQuery结合jQuery.cookie.js插件实现换肤功能示例
- jQuery插件 -- Cookie插件jquery.cookie.js(转)
- JQuery cookie插件 完整源代码 jquery.cookie.js
- jQuery插件 -- Cookie插件jquery.cookie.js
- 原生js和jquery两种处理cookie的插件介绍
- jQuery.cookie.js插件了解及使用方法
- Juery插件-- jquery.cookie.js
- jQuery插件 -- Cookie插件jquery.cookie.js
- jQuery插件 -- Cookie插件jquery.cookie.js
- jQuery插件 -- Cookie插件jquery.cookie.js(转)
- jQuery插件 -- Cookie插件jquery.cookie.js
- 原生 JS 和 Jquery 处理 cookie 的插件介绍
- jquery插件--Cookie插件jquery.cookes.js
- 管理Cookie的插件——jquery.cookie.js
- 使用jquery.cookie.js插件实现记住密码功能
- jQuery插件 -- Cookie插件jquery.cookie.js(转)
- JQuery 插件:、jQuery.Cookie.js
- jquery.cookie.js是jquery管理cookie的插件
- jquery.cookie.js插件使用方法
- jQuery实现换肤功能(使用cookie.js插件)