js对Cookie的读写操作
//读Cookie function getCookie(objName) {//获取指定名称的cookie的值 var arrStr = document.cookie.split("; "); for (var i = 0; i < arrStr.length; i++) { var temp = arrStr[i].split("="); if (temp[0] == objName) return unescape(temp[1]); } return ""; } //设置cookie的值 function setCookie(cname, cvalue, exdays) { var d = new Date(); console.log(cname + '/' + cvalue + '/' + exdays) d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toGMTString(); document.cookie = cname + "=" + escape(cvalue) + "; " + expires; console.log(document.cookie); }
本文来自博客园,作者:方金,转载请注明原文链接:https://www.cnblogs.com/Gold-fangjin/p/5953904.html