jquery用cookie保存我设置的body背景颜色,下面这样写怎么没用呢? 30
2015-04-16 · 知道合伙人互联网行家
关注
展开全部
//要使用cookie, 前提是浏览器支持cookie。基本的 操作方法
function getCookieVal(offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
{
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
}
function setCookie(name, value) {
var today = new Date();
var expires = new Date();
expires.setTime(today.getTime() + 1000*60*60*24*365);
document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString();
}
function delCookie(name)
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = getCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function getCookie(name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
////////////////////////////////////////
保存用setCookie 如setCookie(userName, 用户名), setCookie(color, 红色)
获取用getCookie 如getCookie(userName), getCookie(color)
function getCookieVal(offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
{
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
}
function setCookie(name, value) {
var today = new Date();
var expires = new Date();
expires.setTime(today.getTime() + 1000*60*60*24*365);
document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString();
}
function delCookie(name)
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = getCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function getCookie(name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
////////////////////////////////////////
保存用setCookie 如setCookie(userName, 用户名), setCookie(color, 红色)
获取用getCookie 如getCookie(userName), getCookie(color)
追问
用jquery不要js 我的那个方法是不是对的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询