国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

js文件Cookie存取值示例代碼

2024-05-06 16:01:19
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了js文件Cookie存取值的使用,需要的朋友可以參考下

復制代碼 代碼如下:


/*
Cookie工具
使用方法:
//存值
var value = "7天";
tools.cookie("day",value, {expires:7}); //將字符串:"7天" 以 "day"這個key保存到cookie中5天
//取值
var v = tools.cookie("day"); //用 "day" 這個key從cookie取出值
*/
tools.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.toGMTString)) {
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.toGMTString(); // 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;
}
};

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 阜新| 建湖县| 南城县| 肇源县| 治县。| 霍城县| 吴桥县| 泗阳县| 慈溪市| 黔西县| 霍林郭勒市| 塔河县| 德州市| 宁阳县| 武城县| 广西| 中江县| 陆河县| 柳林县| 曲松县| 沾化县| 耿马| 鄂州市| 土默特左旗| 岳普湖县| 临西县| 宾川县| 古蔺县| 城固县| 泗阳县| 嘉定区| 千阳县| 正蓝旗| 北辰区| 微山县| 平陆县| 将乐县| 鲁甸县| 平远县| 永春县| 丹阳市|