(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;
}
摘自 南南的空间