📄 cookie.js
字号:
// 167-279-1
/* @some operations on cookie,include set,get and delete
* if the blowser doesn't support cookie,it will throw a exception.
* toCheckIsSupportCookie,检验是否支持cookie,默认不检验
*/
function Cookie(toCheckIsSupportCookie){
if(toCheckIsSupportCookie==true && !this.tstCookie()){
throw new Error("this blowser doesn't support cookie");
}
}
/* @set cookie
* name,cookie's name;value,cookie's value;these two arguments are necessary.
* expires,cookie's expires time;
*/
Cookie.prototype.setCookie=function(name,value,expires,path,domain,secure){
if(arguments.length>=2){
var cookie=name+"="+encodeURIComponent(value);
if(expires){
cookie+=";expires="+expires.toGMTString();
}
if(path){
cookie+=";path="+path;
}
if(domain){
cookie+=";domain="+domain;
}
if(secure){
cookie+=";secure";
}
document.cookie=cookie;
}else{
throw new Error("the arguments name and value are necessary");
}
}
/* @get cookie
* name,cookie's name.
*/
Cookie.prototype.getCookie=function(name){
var sRE="(?:; )?"+name+"=([^;]*);?";
var oRE=new RegExp(sRE);
if(oRE.test(document.cookie)){
return decodeURIComponent(RegExp["$1"]);
}else{
return null;
}
}
/* @delete cookie
* name,cookie's name,it's necessary.
* if set cookie include path and domain arguments,
* delete cookie named name,also must include path and domain the same as setted value.
*/
Cookie.prototype.delCookie=function(name,path,domain){
this.setCookie(name,"",new Date(0),path,domain);
}
/* @test whether the blowser supports cookie or not
*/
Cookie.prototype.tstCookie=function(){
this.setCookie("testCookie","testCookie");
if("testCookie"==this.getCookie("testCookie")){
this.delCookie("testCookie");
return true;
}else{
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -