1 function setCookie(name, value, hours){ 2 var exp = new Date(); //new Date("December 31, 9998"); 3 exp.setTime(exp.getTime() + hours*60*60*1000); 4 document.cookie = name + "="+ encodeURIComponent(value) + ";expires=" + exp.toGMTString(); 5 } 6 function getCookie(name){ //读取时,忽略键名大小写 7 var reg = new RegExp(["(?:^| )", name, "=([^;]*)"].join(""),"i"), 8 arr = document.cookie.match(reg); 9 return arr ? decodeURIComponent(arr[1]) : null; 10 }