详细解决方案
JS:cookies 存、取、剔除实例
热度:450 发布时间:2012-11-26 11:48:50.0
JS:cookies 存、取、删除实例
?
function
SetCookie(name,value)
|
05
|
exp.setTime(exp.getTime() +
Days*24*60*60*1000);
|
06
|
document.cookie = name +
"="
+
escape (value) +
";expires="
+ exp.toGMTString();
|
08
|
function
getCookie(name)
|
10
|
var
arr = document.cookie.match(
new
RegExp(
"(^|
)"
+name+
"=([^;]*)(;|$)"
));
|
11
|
if
(arr !=
null
)
return
unescape(arr[2]);
return
null
;
|
14
|
function
delCookie(name)
|
17
|
exp.setTime(exp.getTime() - 1);
|
18
|
var
cval=getCookie(name);
|
19
|
if
(cval!=
null
)
document.cookie= name +
"="
+cval+
";expires="
+exp.toGMTString();
|