我已经制作了一个cookie代码,但是需要能够在整个网站上访问cvalue。 这是写cookie代码:
function setCookie(cname,cvalue) {
var d = new Date();
d.setTime(d.getTime() + (1*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname+"="+cvalue+"; "+expires;
}
然后收到cookie代码:
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) != -1) {
return c.substring(name.length, c.length);
}
}
return "";
}
感谢您的帮助