js操作cookie的函数
///设置cookie
function setCookie(NameOfCookie, value, expiredays)
{
var ExpireDate = new Date();
ExpireDate.setTime(ExpireDate.getTime() +
(expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" +
escape(value) + ((expiredays == null) ? "": "; expires=" +
ExpireDate.toGMTString());
}
///获取cookie值
function
getCookie(NameOfCookie) {
if (document.cookie.length > 0) {
begin =
document.cookie.indexOf(NameOfCookie + "=");
if (begin != -1) {
begin
+= NameOfCookie.length + 1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return
unescape(document.cookie.substring(begin, end));
}
}
return
null;
}
///删除cookie
function delCookie(NameOfCookie) {
if
(getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" + ";
expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。