jQuery-Cookie.插件运用
来源:互联网 发布:三菱数控系统编程手册 编辑:程序博客网 时间:2024/06/11 12:16
提供方便方法操作cookie :
$.cookie('the_cookie'); // 获得cookie
$.cookie('the_cookie', 'the_value'); // 设置cookie
$.cookie('the_cookie', 'the_value', { expires: 7 }); //设置带时间的cookie
$.cookie('the_cookie', '', { expires: -1 }); // 删除
$.cookie('the_cookie', null); // 删除 cookie
$.cookie('the_cookie'); // 获得cookie
$.cookie('the_cookie', 'the_value'); // 设置cookie
$.cookie('the_cookie', 'the_value', { expires: 7 }); //设置带时间的cookie
$.cookie('the_cookie', '', { expires: -1 }); // 删除
$.cookie('the_cookie', null); // 删除 cookie
------js代码--------------------------------------------------------------------------------------------------------
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
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
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;
}
};
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
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
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.插件运用
- jQuery.cookie插件 cookie
- jQuery.cookie插件 cookie
- jQuery插件 -- Cookie插件
- jQuery插件 -- Cookie插件jquery.cookie.js
- jQuery插件 -- Cookie插件jquery.cookie.js
- jQuery插件 -- Cookie插件jquery.cookie.js
- jQuery插件 -- Cookie插件jquery.cookie.js
- Cookie操作插件 jQuery.Cookie
- Cookie操作插件 jQuery.Cookie
- jQuery - plugin插件 - Cookie
- Jquery中的Cookie插件
- jQuery插件:操作cookie
- jQuery.Cookie插件源码
- 扩展Jquery cookie插件
- JQUERY---cookie插件用法
- Jquery插件cookie操作
- jQuery插件之Cookie
- 图解使用VMware workstation搭建NAT测试环境
- 设置appfuse项目中的smtp设置
- Cuda日记
- 注册表不能写入导致不能安装office问题分析
- 关于查找方法(Find方法)的应用
- jQuery-Cookie.插件运用
- C++的全局键盘HOOK屏蔽Win键
- ASP.NET数据绑定概述和语法
- VB十七种可用一行代码完成的技巧
- 关于编码的方式控制IIS问题总结!
- 外高桥CIO亲授秘诀:灵动业务 让IT先行
- orac le -修改表空间大小
- URLWriting 重写原理
- oracle中length()与lengthb()区别