同一页面不断刷新,如何在js中定义全局变量?
在一个页面中,如何在js中定义一个全局变量,以后不断赋值,刷新后可以不断的取出新值?
------解决方案--------------------cookie
function getcookievalue(sname){
var svalue= " ";
var sname=sname+ "= ";
if(document.cookie.length> 0){
offset=document.cookie.indexOf(sname);
if(offset!=-1){
offset+=sname.length;
end=document.cookie.indexOf( "; ",offset);
if(end==-1)end=document.cookie.length;
svalue=unescape(document.cookie.substring(offset,end))
}
}
return svalue;
}
function setcookievalue(sname,svalue){
var expire= " ";
expire=new Date((new Date()).getTime()+31536000);
expire= "; expires= "+expire.toGMTString();
document.cookie=sname+ "= "+escape(svalue)+expire;
}