js 设置cookie与 获取cookie函数
时间:2011-01-18 来源:秩名
我们利用readcookie来读取,利用setcookie设置或删除cookie值。
*/
function readcookie ( cookiename )
{
var thecookie=""+document.cookie;
var ind=thecookie.indexof(cookiename);
if (ind==-1 || cookiename=="") return "";
var ind1=thecookie.indexof(';',ind);
if (ind1==-1) ind1=thecookie.length;
return unescape(thecookie.substring(ind+cookiename.length+1,ind1));
}
function setcookie(cookiename,cookievalue,ndays)
{
var today = new date();
var expire = new date();
if (ndays==null || ndays==0) ndays=1;
expire.settime(today.gettime() + 3600000*24*ndays);
document.cookie = cookiename+"="+escape(cookievalue)
+ ";expires="+expire.togmtstring();
}
标签分类: