扩展Jquery cookie插件
啥也不说了,上代码:
/** * 扩展了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");
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。