JS控制Cookies
直接上代码了...比较简单!
1 function getCookie(key){ 2 var arrStr = document.cookie.split(";"); 3 for(var i = 0; i < arrStr.length; i++){ 4 var tmp = arrStr[i].split("="); 5 if(tmp[0].trim() == key.trim()){ 6 return tmp[1]; 7 } 8 } 9 }10 11 function addCookie(key, value){12 var str = key + "=" + escape(value);13 var date = new Date();14 var ms = 365 * 24* 60 * 60;15 date.setTime(date.getTime()+ms);16 str += ";expires="+date.toGMTString();17 document.cookie = str;18 }
TAG: