js与后台使用cookie传值问题?
我在js中要把值赋给cookie,然后在后台用代码取出此cookie中的值,请大家帮忙代码详细点,谢谢......
我在js中要把值赋给cookie,然后在后台用代码取出此cookie中的值,请大家帮忙代码详细点,谢谢...
展开
1个回答
2013-04-15
展开全部
下面是代码示例//赋值给cookiefunction setCookies(name,value)
{
var Days = 30; //此 cookie 将被保存 30 天
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape(value) +";expire*="+ **p.toGMTString();
}
//读取cookiefunction getCookies(name)
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
//删除cookiefunction delCookies(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie=name +"="+cval+";expire*="+**p.toGMTString();
}
{
var Days = 30; //此 cookie 将被保存 30 天
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape(value) +";expire*="+ **p.toGMTString();
}
//读取cookiefunction getCookies(name)
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
//删除cookiefunction delCookies(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie=name +"="+cval+";expire*="+**p.toGMTString();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询