window.localData = {};window.historyData = {};jquery(function () { localData = (function () { var hname = "localData" + (new Date().getTime()); return { //other cookie; //storage() || userData() || time: 10,date: function (day) { var date = new Date(); date.setTime(date.getTime() + (parseInt(day) || parseInt(this.time) || 10) * 24 * 3600 * 1000); return date.toGMTString(); },set: function (key,val) { if (!!key) { document.cookie = key + "=" + encodeURIComponent(val) + "; path=/; "; } return this; },get: function (key) { if (!!key) { var arrcookie = (document.cookie || "").split("; "); for (var i = 0; i < arrcookie.length; i++) { var arr = arrcookie[i].split("="); if (arr[0] == key) return decodeURIComponent(arr[1]); } return null; } },remove: function (key) { if (!!key) { document.cookie = key + "=" + encodeURIComponent("") + "; path=/; expires=" + this.date(-10); } return this; } }; })(); historyData = { local: localData,type: Object.prototype.toString,isArray: Array.isArray || function (obj) { return this.type.call(obj) === "[object Array]"; },isObj: function (data) { return typeof data === "string" || typeof data === "number"; },join: function (Json,depth,flag) { var str = "",key = "",val = ""; for (key in Json) { str += flag === 1 ? this.JsonToStr(key,true) + ":" : ""; str += this.JsonToStr(Json[key],true) + ","; } return str.lastIndexOf(",") === str.length - 1 ? str.substring(0,str.length - 1) : str; },JsonToStr: function (Json,index = 1,depth = depth || 10; if (index++ > depth) return ""; if (typeof Json === "string" || typeof Json === "number") { if (!flag) { return (str + (Json || "")).replace(/([\\\"])/g,"\\$1"); } else { return ‘\"‘ + (str + (Json || "")).replace(/([\\\"])/g,"\\$1") + ‘\"‘; } } if (this.isArray(Json)) { return str + "[" + this.join(Json,0) + "]"; } else if (typeof Json === "object") { return str + "{" + this.join(Json,1) + "}"; } },val,depth) { this.local.set(key,this.JsonToStr(val,depth)); },get: function (key) { var val = this.local.get(key); if (!val) return null; if ((val.indexOf("{") === 0 && val.lastIndexOf("}") === val.length - 1) || (val.indexOf("[") === 0 && val.lastIndexOf("]") === val.length - 1)) try { val = eval(‘(‘ + val + ‘)‘); } catch (e) { } return val; },removeAll: function (key) { this.local.remove(key); } }; window.localData = localData; window.historyData = historyData;});@H_192_301@ 总结
以上是内存溢出为你收集整理的整理---定义全局产品cookie存取全部内容,希望文章能够帮你解决整理---定义全局产品cookie存取所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)