/** * js 设cookies * @param name 存储的名称 列如 name = 'one_name'; * @param value 存储的值 列如 value = '123' * @param expiredays 过期时间 列如 希望 2分钟过期 expiredays = 60 * 2000 ——> exp.setTime(exp.getTime() + 60 * 2000); */ setCookie:function(name,value,expiredays){ var exp = new Date(); exp.setTime(exp.getTime() + expiredays);//过期时间 document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); console.log(name + "=" + escape(value) + ";expires=" + exp.toGMTString()); }, /** * 获取cookies * @param name 要获取的键名 * @returns {string} */ getCookie:function(name) { if (document.cookie.length > 0) { var start = document.cookie.indexOf(name + "="); if (start != -1){ var startIndex = start + name.length + 1; var endIndex = document.cookie.indexOf(";", startIndex) if (endIndex == -1) endIndex = document.cookie.length return unescape(document.cookie.substring(startIndex, endIndex)) } } return "" },