js 封装cookie操作的函数代码
人气:0核心代码:
复制代码 代码如下:
var cookie={
setCookie:function (name, value, iDay) {
var oDate = new Date();
oDate.setDate(oDate.getDate()+iDay);
document.cookie = name+'='+value+';expires='+oDate;
},
getCookie:function (name) {
var arr = document.cookie.split('; ');
for (var i = arr.length - 1; i >= 0; i--) {
var arr2 = arr[i].split('=');
if(arr2[0]===name){
return arr2[1];
}
}
return '';
},
removeCookie:function (name) {
cookie.setCookie(name,1,-1);
}
};
测试:
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
加载全部内容