Cookie完整的公用封装方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var Cookie-function = {
setCookie: function(name, value) {
//写cookies
var d = new Date();
d.setTime(d.getTime() + (7 * 24s * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = name + "=" + value + "; " + expires;
},
getCookie: function(cname) {
//读取cookies
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
},
delCookie: function(name) {
//删除cookies
f.setCookie(name, "", -1);
},
}