define(function(){
//write cookie
this.setCookie = function(key,value,expiredays,domain){
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = key + “=” + escape(value) + “;expires=” + exdate.toGMTString() + “;path=/;domain=” + domain;
}
//read cookie
this.getCookie = function(key) {
if(document.cookie.length===0){
return '';
}
var _start = document.cookie.indexOf(key + "=");
if(_start != -1){
_start += key.length + 1;
_end = document.cookie.indexOf(";",_start);
if(_end===-1){
_end = document.cookie.length;
}
return unescape(document.cookie.substring(_start,_end))
}
}
//delete cookie
this.delCookie = function(key){
var value = getCookie(key),
exdate = new Date();
exdate.setDate(exdate.getTime() - 1);
if(value && value!=''){
document.cookie = key + '=' + escape(value) +';path=/;expires=' + exdate.toGMTString();
}
}
return this;
})
本文介绍了一种使用JavaScript在客户端进行Cookie操作的方法,包括设置、获取及删除Cookie。通过这些方法可以实现用户状态保持等功能。
4159

被折叠的 条评论
为什么被折叠?



