国产探花免费观看_亚洲丰满少妇自慰呻吟_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;
}
};

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

圖片精選

主站蜘蛛池模板: 邢台市| 乐安县| 万荣县| 虹口区| 荔浦县| 大洼县| 文登市| 邻水| 千阳县| 齐齐哈尔市| 南雄市| 手机| 独山县| 萍乡市| 广南县| 自治县| 天门市| 和林格尔县| 东港市| 甘肃省| 会昌县| 万安县| 乐平市| 马山县| 华宁县| 罗甸县| 石渠县| 玛曲县| 衡阳市| 黄冈市| 邓州市| 襄城县| 两当县| 津市市| 梅河口市| 彰化市| 德化县| 邵阳市| 合肥市| 滦平县| 泸西县|