JS cookie

名字 密码 日期
用来识别用户
一个简单的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
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>刘宝宝hello</title>
<script>
function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=")
if (c_strat != -1) {
c_strat = c_strat + c_name.length + 1;
c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) c_end = document.cookie.length;
return;
unescape(document.cookie.sbstring(c_strat, c_end))
}
}
return ""
}
function setCookie(c_name,value,expiredays) { //cookie的名称、值、过期时间
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+"="+exdate(value)+((expiredays==null)?"":";expiress="+exdate.toGMTstring())
}
</script>
</head>
<body >
</body>
</html>