扩展Jquery cookie插件

来源:互联网 发布:免费seo软件 编辑:程序博客网 时间:2024/05/17 05:55

啥也不说了,上代码:

/** * 扩展了jQuery cookie */jQuery.cookie = function(name, value, options) {    if (typeof value != 'undefined') {         options = options || {};        if (value === null) {            value = '';            options = $.extend({}, options);             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       return getCookie(name);    }};/** * 获取Cookie值 */function getCookie(b) {var d = b + "=";var e = document.cookie.indexOf(d);if (e == -1) {return null;}var a = document.cookie.indexOf(";", e + d.length);if (a == -1) {a = document.cookie.length;}var c = document.cookie.substring(e + d.length, a);return unescape(c);}

调用方式

jQuery.cookie("__jforumSSOCookieNameUser__","test");


2 0