function SetCookie(name, value) {
var exp = new Date();
exp.setTime(exp.getTime() + 3 * 24 * 60 * 60 * 1000); //3天过期
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
return true;
};
function getCookie(name) {
var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
if (arr != null) return arr[2]; return null;
};
var currentServiceAliasName = getCookie("appName");
var displayName = "";
if (currentServiceAliasName != null && currentServiceAliasName != "" && currentServiceAliasName != "undefined")
displayName = decodeURIComponent(currentServiceAliasName) + " . " + counterName;
else
displayName = counterName;
decodeURIComponent , 用这个转换一下;
本文介绍了一种使用JavaScript实现设置与获取Cookie的方法。通过示例代码展示了如何设置一个三天后过期的Cookie,并提供了从当前文档中读取特定Cookie(如appName)并进行解码的具体步骤。
1723

被折叠的 条评论
为什么被折叠?



