javascript cookie
//设置cookie function setCookie(name, value, day) { var date=new Date(); date.setDate(date.getDate() + day); document.cookie = name + "=" + escape(value) + ((day == null) ? "" : ";expires=" + date.toGMTString()); } setCookie("username", "perter", 3); setCookie("password", "123", 3); //获取cookie function getCookie(name){ var arr1 = document.cookie.split("; "); var j =0; for (j; j<arr1.length; j++) { var arr2 = arr1[j].split("="); if (arr2[0] == name) { return arr2[1]; } } return ""; } alert(getCookie("username")); //perter //删除cookie function removeCookie(name) { setCookie(name, "", -1); } removeCookie("username"); alert(getCookie("username")); //返回空字符串