1
<scriptlanguage="JScript">
2
functionCookie(delim){
3
this._Cookie=[];
4
this.Load=function(){
5
if(document.cookie.indexOf(";")!=-1){
6
var_sp,_name,_tp,_tars,_tarslength;
7
var_item=document.cookie.split(";");
8
var_itemlength=_item.length;
9
while(_itemlength>0){
10
_sp=_item[--_itemlength].split("=");
11
_name=_sp[0];
12
_tp=_sp[1].split(",");
13
_tars=_tp.slice(1,_tp.length);
14
this._Cookie[_name]=[];
15
this._Cookie[_name]=_tars;
16
this._Cookie[_name]["timeout"]=_tp[0];
17
}
18
returntrue;
19
}
20
returnfalse;
21
}
22
this.Save=function(){
23
var_str,_ars,_mars,_marslength,timeout,i,key;
24
for(keyinthis._Cookie){
25
if(!this._Cookie[key])return;
26
_str=[];
27
_mars=CookieClass._Cookie[key];
28
_marslength=_mars.length;
29
for(i=0;i<_marslength;i++)_str[_str.length]=escape(_mars[i]);
30
document.cookie=key+"="+_mars["timeout"]+(_str.length>0?",":"")+_str+(_mars["timeout"]==0?"":";expires="+newDate(parseInt(_mars["timeout"])).toGMTString());
31
}
32
33
}
34
this.GetCookieCount=function(){
35
var_length=0,key;
36
for(keyinthis._Cookie)_length++;
37
return_length;
38
}
39
this.Create=function(name,days){
40
days=days?days:0;
41
if(!this._Cookie[name])this._Cookie[name]=[];
42
this._Cookie[name]["timeout"]=days!=0?newDate().getTime()+parseInt(days)*86400000:0;
43
}
44
this.Modify=function(name,days){
45
this.Create(name,days);
46
}
47
this.GetTime=function(name){
48
returnnewDate(parseInt(this._Cookie[name]["timeout"]));
49
}
50
this.Delete=function(name){
51
this.Create(name,0);
52
}
53
this.AddItem=function(name,value){
54
this._Cookie[name][this._Cookie[name].length]=value;
55
}
56
this.DelItem=function(name,index){
57
var_ttime=this._Cookie[name]["timeout"];
58
this._Cookie[name]=this._Cookie[name].slice(0,index).concat(this._Cookie[name].slice(parseInt(index)+1,this._Cookie[name].length));
59
this._Cookie[name]["timeout"]=_ttime;
60
}
61
this.GetCount=function(name){
62
returnthis._Cookie[name].length;
63
}
64
this.GetItem=function(name,index){
65
returnthis._Cookie[name][index];
66
}
67
}
68
</script>
69
<scriptlanguage="JScript">
70
varCookieClass=newCookie();
71
if(!CookieClass.Load()){
72
CookieClass.Create("Pass",1);
73
CookieClass.AddItem("Pass","Ps1");
74
CookieClass.AddItem("Pass","Ps2");
75
CookieClass.AddItem("Pass","Ps3");
76
CookieClass.AddItem("Pass","Ps4");
77
CookieClass.DelItem("Pass",1);
78
CookieClass.Save();
79
}
80
alert("Cookie过期时间:"+CookieClass.GetTime("Pass").toLocaleString());
81
alert(document.cookie);
82
</script>
83
<script>
84
functioneyunCookie()
85
{this.key="";//初始化key。
86
this.value="";//初始化key'svalue。
87
this.expires=0;//初始化cookie的有效时间,单位毫秒。
88
this.init=function()//对象初始化
89
{this.key="";
90
this.value="";
91
this.expires=0;
92
}
93
this.set=function(key,value,expires)//设置cookie
94
{if(this.key=="")this.key=key;
95
if(this.value=="")this.value=value;
96
if(this.expires<=0)this.expires=expires;
97
if(this.key==""||typeof(this.key)!="string")
98
{alert("请先设置欲保存的cookie名称!");
99
this.init();
100
returnfalse;
101
}
102
if(this.key.match(/[,;]/))
103
{alert("cookie名称中不能包含“,”、“;”或空格!");
104
this.init();
105
returnfalse;
106
}
107
if(this.value.toString().match(/[,;]/)||typeof(this.value)=="undefined")
108
{alert("cookie值中不能包含“,”、“;”或空格!");
109
this.init();
110
returnfalse;
111
}
112
if(this.expires<=0||typeof(this.expires)!="number")
113
{alert("请先正确设置cookie的有效时间!");
114
this.init();
115
returnfalse;
116
}
117
varcookie=document.cookie;
118
if(cookie.indexOf(this.key+"=")!=-1)
119
{if(!confirm("欲保存的cookie名称已经存在,是否要进行替换?"))
120
{this.init();
121
returnfalse;
122
}
123
}
124
vardt=newDate();
125
dt.setTime(dt.getTime()+this.expires);
126
document.cookie=this.key+"="+this.value+";expires="+dt.toGMTString();
127
this.init();
128
returntrue;
129
}
130
this.get=function(key)//取得名为key的cookie的值
131
{if(key==""||key.match(/[,;]/))
132
{alert("请正确设置欲查找的cookie名称!")
133
returnfalse;
134
}
135
varcookie=document.cookie;
136
varstart=cookie.indexOf(key+"=");
137
if(start==-1)
138
{alert("欲查找的cookie不存在!")
139
returnfalse;
140
}
141
varend=cookie.indexOf(";",start);
142
if(end==-1)
143
end=cookie.length;
144
vargetCookie=cookie.substring(start+key.length+1,end);
145
alert("cookie:"+key+"的值为"+getCookie);
146
returngetCookie;
147
}
148
this.showAll=function(){alert("共有以下cookie对:\n"+document.cookie.split(";").toString().replace(/,/g,"\n"));}//显示所有cookie
149
this.del=function(key)//删除名为key的cookie
150
{if(key==""||key.match(/[,;]/))
151
{alert("请正确设置欲删除的cookie名称!")
152
returnfalse;
153
}
154
vardt=newDate();
155
dt.setTime(dt.getTime());
156
document.cookie=key+"=eyunDelete;expires="+dt.toGMTString();
157
this.init();
158
returntrue;
159
}
160
this.destroy=function()//销毁所有cookie
161
{vardt=newDate();
162
dt.setTime(dt.getTime());
163
while(document.cookie!="")
164
document.cookie=document.cookie+";expires="+dt.toGMTString();
165
this.init();
166
returntrue
167
}
168
}
169
varcookieTest=neweyunCookie()
170

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

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170