1 //设置cookie 2 function setCookie(name,value,time){ 3 var exdate=new Date(); 4 exdate.setTime(exdate.getTime()+time * 1000); 5 document.cookie=name+"="+escape(value)+((time==null)? "":";expires="+exdate.toGMTString()) 6 } 7 8 //获取cookie 9 function getCookie(name){ 10 if(document.cookie.length>0){ 11 var c_start=document.cookie.indexOf(name + "="); 12 if(c_start!=-1){ 13 c_start=c_start+name.length+1; 14 c_end=document.cookie.indexOf(";",c_start); 15 if(c_end==-1){ 16 c_end=document.cookie.length; 17 } 18 return unescape(document.cookie.substring(c_start,c_end)); 19 } 20 } 21 return ""; 22 } 23 24 //删除cookie 25 function removeCookie(name){ 26 var value = getCookie(name); 27 if(value == ""){ 28 return; 29 } 30 //获取当前时间 31 var exdate=new Date(); 32 //设置过期时间为过去的时间 33 exdate.setTime(exdate.getTime()-1000); 34 document.cookie = name+"="+escape(value)+";expires="+exdate.toGMTString() 35 }