jQuery.cookie>jQuery.c , value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
) {
value = '';
ires = '';
if (options.expires && (typeof options.expires == ' number' || options.expires.toUTCString)) {
var date;
date = new Date();
date.setTime (date.getTime() (options.expires * 24 * 60 * 60 * 1000));
} > }
expires = '; expires=' date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var domain = options.domain ? '; domain=' options.domain : '';
var secure = options.secure ? '; secure' : ''; } else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name 0 name.length 1) == (name '= ')) {
cookieValue = decodeURIComponent(cookie.substring(name.length 1)); }
}};
然後看了下Discuz!中對cookie的操作方法
如下,發現少了個遍歷用;分割的數組的處理
複製程式碼
程式碼如下:
function getcookie(name) {
var cookie_start = document.cookie.indexOf(name);
var cookie_end = document.cookie.indexOf(";", cookie_start);var expires = new Date();
expires.setTime(expires.getTime()秒);
document.cookie = escape(cookieName) ' =' escape(cookieValue) )
(expires ? '; expires=' expires.toGMTString() : '')
(path ? '; path=' 路徑: '/')
(domain ? '; 網域=' 網域: '')
(安全? '; 安全' : '');
}