js Cookie的操作
js操作Cookie
js Cookie的操作
用的时候跟用session差不多
存值 Session("key","伤心木乃伊JS操作Cookes");
取值 var Value=Session("key");
js Cookis的操作
function StringTrim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } // function Session(ckName, ckValue, ckDate) { if (!ckName && !ckValue && !ckDate) { return false; } //写入cookies else if (ckName && ckValue) { //设置过期时间 var day = new Date(); var expDay = new Date(); if (!ckDate || ckDate == 'undefined') ckDate = 0; expDay.setTime = day.getTime() * 3600000 * 24 * ckDate; try{ document.cookie = escape(StringTrim(ckName)) + '=' + escape(ckValue) + ';expiress' + expDay.toGMTString(); } catch(ee){ return false;} return true; } //读取Cookie else if (ckName && !ckValue) { ckName = escape(ckName); var cookieList = document.cookie.split(';'); for (var j = 0; j < cookieList.length; j++) { var s = StringTrim(cookieList[j].split('=')[0]); if (StringTrim(ckName) == StringTrim(cookieList[j].split('=')[0])) { return (cookieList[j].split('=')[1]); } } return ''; } }
存值 Session("key","伤心木乃伊JS操作Cookes");
取值 var Value=Session("key");
js Cookis的操作