Skip to content

Commit 2b70c96

Browse files
committed
cookie的基础与应用
1 parent 433cd0d commit 2b70c96

File tree

15 files changed

+252
-177
lines changed

15 files changed

+252
-177
lines changed

JavaScript系列视频资料/智能社视频材料 - COOKIE基础与应用/记录/Date.html

Lines changed: 0 additions & 17 deletions
This file was deleted.

JavaScript系列视频资料/智能社视频材料 - COOKIE基础与应用/记录/Date2.html

Lines changed: 0 additions & 17 deletions
This file was deleted.

JavaScript系列视频资料/智能社视频材料 - COOKIE基础与应用/记录/cookie.html

Lines changed: 0 additions & 16 deletions
This file was deleted.

JavaScript系列视频资料/智能社视频材料 - COOKIE基础与应用/记录/cookie过期时间.html

Lines changed: 0 additions & 19 deletions
This file was deleted.

JavaScript系列视频资料/智能社视频材料 - COOKIE基础与应用/记录/封装cookie.html

Lines changed: 0 additions & 49 deletions
This file was deleted.

JavaScript系列视频资料/智能社视频材料 - COOKIE基础与应用/记录/记住上一次的用户名.html

Lines changed: 0 additions & 59 deletions
This file was deleted.

cookie基础与应用/Date.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script>
9+
var oDate=new Date();
10+
11+
oDate.setDate(32);
12+
13+
alert(oDate.getFullYear()+'-'+(oDate.getMonth()+1)+'-'+oDate.getDate());
14+
</script>
15+
</head>
16+
<body>
17+
18+
</body>
19+
</html>

cookie基础与应用/Date2.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script>
9+
var oDate=new Date();
10+
11+
oDate.setDate(oDate.getDate()+800);
12+
13+
alert(oDate.getFullYear()+'-'+(oDate.getMonth()+1)+'-'+oDate.getDate());
14+
</script>
15+
</head>
16+
<body>
17+
18+
</body>
19+
</html>

cookie基础与应用/cookie.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script>
9+
document.cookie='user=blue';
10+
document.cookie='pass=123';//不会覆盖之前的,是添加
11+
12+
alert(document.cookie);
13+
</script>
14+
</head>
15+
<body>
16+
17+
</body>
18+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script>
9+
var oDate=new Date();
10+
11+
oDate.setDate(oDate.getDate()+14);
12+
13+
document.cookie='user=blue;expires='+oDate;
14+
//document.cookie='pass=123';//不会覆盖之前的,是添加
15+
16+
alert(document.cookie);
17+
</script>
18+
</head>
19+
<body>
20+
21+
</body>
22+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script>
9+
function setCookie(name,value,iDay)
10+
{
11+
var oDate=new Date();
12+
oDate.setDate(oDate.getDate()+iDay);
13+
14+
document.cookie=name+'='+value+';expires='+oDate;
15+
}
16+
17+
setCookie('userName','baihuirong',365);
18+
setCookie('password','123456',14);
19+
</script>
20+
</head>
21+
<body>
22+
23+
</body>
24+
</html>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script>
9+
function setCookie(name,value,iDay)
10+
{
11+
var oDate=new Date();
12+
oDate.setDate(oDate.getDate()+iDay);
13+
14+
document.cookie=name+'='+value+';expires='+oDate;
15+
}
16+
17+
function getCookie(name)
18+
{
19+
var arr=document.cookie.split('; ');//字符串分割
20+
21+
for(var i=0;i<arr.length;i++)//先拆,拆完后比较
22+
{
23+
var arr2=arr[i].split('=');
24+
if(arr2[0]==name)
25+
{
26+
return arr2[1];
27+
}
28+
}
29+
30+
return '';
31+
}
32+
33+
function removeCookie(name)
34+
{
35+
setCookie(name,1,-1);
36+
}
37+
setCookie('userName','baihuirong',365);
38+
setCookie('password','123456',14);
39+
40+
removeCookie('userName');
41+
alert(document.cookie);
42+
</script>
43+
</head>
44+
<body>
45+
46+
</body>
47+
</html>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script>
9+
function setCookie(name,value,iDay)
10+
{
11+
var oDate=new Date();
12+
oDate.setDate(oDate.getDate()+iDay);
13+
14+
document.cookie=name+'='+value+';expires='+oDate;
15+
}
16+
17+
function getCookie(name)
18+
{
19+
var arr=document.cookie.split('; ');//字符串分割
20+
21+
for(var i=0;i<arr.length;i++)//先拆,拆完后比较
22+
{
23+
var arr2=arr[i].split('=');
24+
if(arr2[0]==name)
25+
{
26+
return arr2[1];
27+
}
28+
}
29+
30+
return '';
31+
}
32+
33+
function removeCookie(name)
34+
{
35+
setCookie(name,1,-1);
36+
}
37+
removeCookie('password');
38+
alert(document.cookie);
39+
</script>
40+
</head>
41+
<body>
42+
43+
</body>
44+
</html>

0 commit comments

Comments
 (0)