-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest6.html
41 lines (35 loc) · 1021 Bytes
/
test6.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 设置cookie封装
function setCookie(key, value, expires) {
let now = new Date();
now.setDate(now.getDate() + expires);
document.cookie = `${key} = ${value}; expires= ${now.toUTCString()}`;
};
// 提取cookie封装
function getCookie() {
let obj = {};
let cookies = document.cookie.split('; ');
cookies.forEach(r => {
let kv = r.split('=');
let key = kv[0];
let val = kv[1];
obj[key] = val;
});
if (key) { return obj[key] }
return obj
}
//删除cookie封装
console.log(function removeCookie(key) {
setCookie(key, null, -1)
});
</script>
</body>
</html>