/*** *获取cookies中的某个变量 *@param: {string} name 需要获取的cookies名称 *@return:{void} *cnosole.log(cookies.get("kugou")) */ get : function(name){ var arr = document.cookie.match(new RegExp("(^|)" + name + "=([^;]*)(;|$)")); if(arr !== null){ return window.unescape(arr[2]); } return null; }, /** *设置变量与值 *@param: {string} name 需要设置的cookies属性名称 *@param: {string} value 需要设置的cookies属性值 *@param: {number} delayHours 过期时间,单位小时,默认为24小时 *@param: {string} path cookies存放路径 以"/"结尾 如果值为"/"则表示全站通用 *@param: {string} domain cookies作用域设置 *@param: {boolean} secure secure值为true时,在http中是无效的,在https中才有效 *console.log(cookies.set("kugou","hello",10)); */ set : function(name,value,delayHours,path,domain,secure){ if(!delayHours){ delayHours = 24; } var exp = new Date(); exp.setTime(exp.getTime() + delayHours*60*60*1000); document.cookie = name + "=" + window.escape(value) + ";expires=" + exp.toGMTString() + (domain?";domain=" + domain:"") + (path?";path=" + path:"") + (secure === true?";secure":""); }, /** *删除cookies变量 *@param: {string} name 需要删除的cookies属性名称 *console.log(cookies.del("kugou")); */ del : function(name){ var exp = new Date(); exp.setTime(exp.getTime() -1); var cval = this.get(name); if(cval !== null){ document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); } } }cookies.set("kugou",abc=5555&webtall=5652222&allbluer=554254,10,"/");