x
1
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>蜜蜂教程(mifengjc.com)</title>
6
</head>
7
<head>
8
<script>
9
function setCookie(cname, cvalue, exdays) {
10
var d = new Date();
11
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
12
var expires = "expires=" + d.toGMTString();
13
document.cookie = cname + "=" + cvalue + "; " + expires;
14
}
15
16
function getCookie(cname) {
17
var name = cname + "=";
18
var ca = document.cookie.split(';');
19
for (var i = 0; i < ca.length; i++) {
20
var c = ca[i].trim();
21
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
22
}
23
return "";
24
}
25
26
function checkCookie() {
27
var user = getCookie("username");
28
if (user != "") {
29
alert("Welcome again " + user);
30
} else {
31
user = prompt("Please enter your name:", "");
32
if (user != "" & user != null) {
33
setCookie("username", user, 30);
34
}
35
}
36
}
37
</script>
38
</head>
39
40
<body onload="checkCookie()"></body>
41
42
</html>