本文共 1830 字,大约阅读时间需要 6 分钟。
js操作cookie
var Cookie = {
setCookie: function(key, value, expiredays) { expiredays = expiredays || 30; //默认30天 var exdate = new Date(); exdate.setDate(exdate.getDate() + expiredays); document.cookie = key + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());},getCookie: function(key) { var arr, reg = new RegExp("(^| )" + key + "=([^;]*)(;|$)");return (arr = document.cookie.match(reg)) ? unescape(arr[2]) : null;},removeCookie: function(key) { var exp = new Date();exp.setTime(exp.getTime() - 1);var cval = this.getCookie(key);if(cval != null)document.cookie = key + "=" + cval + ";expires=" + exp.toGMTString();}};Cookie.setCookie('name', 'staven');Cookie.removeCookie('name');Cookie.getCookie('name');</code>使用localstorage存储数据<code>
var LocalStorage = { getLs: function(str) { var msgArr = localStorage.getItem(str);return !msgArr ? msgArr = [] : msgArr = msgArr.split(',');},/**转载于:https://blog.51cto.com/3928405/2154644