jQuery写入读取Cookie插件
来源:互联网 发布:新手如何面试美工助理 编辑:程序博客网 时间:2024/05/22 04:36
强大的jquery居然没有操作cookie相关的函数
特地去官方讨论区去看了下,发现已经有人建议,个人预期下个版本也就是1.2中会加入读取cookie,写入cookie的函数
既然现在没有那只好去寻找下jquery的插件来实现了,在jquery的插件区很容易就找到啦
现在给大家分享一下,顺便记录下做备份。
在http://docs.jquery.com/Plugins这里找到的
感兴趣的朋友可以到原作者这里看看
http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/
jQuery操作cookie的插件,大概的使用方法如下
example $.cookie(’the_cookie’, ‘the_value’);
设置cookie的值
example $.cookie(’the_cookie’, ‘the_value’, {expires: 7, path: ‘/’, domain: ‘jquery.com’, secure: true});
新建一个cookie 包括有效期 路径 域名等
example $.cookie(’the_cookie’, ‘the_value’);
新建cookie
example $.cookie(’the_cookie’, null);
删除一个cookie
代码如下
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
- jQuery写入读取Cookie插件
- JavaScript中jQuery写入读取Cookie插件
- jQuery的cookie插件使用,jQuery操作cookie,写入,读取,删除
- Jquery cookie操作示例,写入cookie,读取cookie,删除cookie
- cookie(读取、写入、删除)基于jquery.cookie.js
- jquery.cookie.js 的使用读取、写入、删除cookie
- jquery.cookie() 方法的使用(读取、写入、删除)
- jquery.cookie() 方法的使用(读取、写入、删除)
- jquery.cookie() 方法的使用(读取、写入、删除)
- jquery.cookie() 方法的使用(读取、写入、删除)
- JQuery.cookie() 方法的使用(读取、写入、删除)
- jquery.cookie() 方法的使用(读取、写入、删除)
- jquery.cookie() 方法的使用(读取、写入、删除)
- jquery.cookie() 方法的使用(读取、写入、删除)
- jquery.cookie() 方法的使用(读取、写入、删除)
- jquery.cookie() 方法的使用(读取、写入、删除)
- jquery.cookie() 方法的使用(读取、写入、删除)
- jquery.cookie() 方法的使用(读取、写入、删除)
- shell下的乱码恢复
- 《 我的青春谁做主》经典台词
- 财政预算紧张情况下10种CRM的实施方法
- 新工作,新生活,新BLOGS
- ssh框架的好处
- jQuery写入读取Cookie插件
- fckeditor配置详解
- Apache Rewrite
- 一个北京人的买房血泪史:我不想一辈子做房奴!
- Apache mod_rewrite 更多介绍
- uchome 功能实现分析(1)
- WCF开发入门的六个步骤
- ssh框架配置
- Symbian C++程序开发中纯虚类的妙用