ITPub博客

首页 > 应用开发 > Java > js cookie操作

js cookie操作

原创 Java 作者:okone96 时间:2007-04-27 14:19:33 0 删除 编辑

cookieObj=function(){}
cookieObj.prototype.clearCookie = function() {
var now = new Date();
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
};

// [Cookie] Sets value in a cookie
cookieObj.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
document.cookie =
escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; expires=' + expires.toGMTString() : '')
+ (path ? '; path=' + path : '')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
};


// [Cookie] Gets a value from a cookie

cookieObj.prototype.getCookie = function(cookieName) {
var cookieValue = '';
var posName = document.cookie.indexOf(escape(cookieName) + '=');
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=').length;
var endPos = document.cookie.indexOf(';', posValue);
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
else cookieValue = unescape(document.cookie.substring(posValue));
}
return (cookieValue);
};

// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {
var str = '';
//找到需要修改的key值key
this.setCookie('co' +key , str);
};

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/750220/viewspace-912610/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: jsquery简单体验
请登录后发表评论 登录
全部评论
  • 博文量
    83
  • 访问量
    198459