(1)首先,介绍一下javascript操作cookie的基础
//去除空格,回车 String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } //设置Cookie function setCookie(c_name, c_value,expiredays) { var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays); document.cookie = c_name + "=" + escape(c_value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()); } //按名字读取Cookie function getCookie(c_name) { if (document.cookie.length>0) { var m_car=document.cookie.split(';'); var value=-1; for (i = 0; i < m_car.length; i++) { if(c_name.toString().Trim()==((m_car[i].split('='))[0]).toString().Trim()) { value = (m_car[i].split('='))[1]; } } } return value; }
浙公网安备 33010602011771号