封装一个cookie方法
var myCookie = {
// 设置cookie
set: function (name, value, date) {
// max-age 要求用户传入的是过期的秒数
document.cookie = name + '=' + value + '; max-age=' + date
},
// 移除cookie
remove: function (name) {
this.set(name, '', 0);
},
// 获取cookie
get: function (name) {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
// [['name','kaivon'],['padding,'30'],['width',40]]
var item = cookies[i].split('=');
if (item[0] == name) {
return item[1];
}
}
}
}