Cookie 设置

function setCookie(cookieName,cookieValue,nDays){
/* 当前日期 */
var today = new Date();
/* 过期时间 */
var expire = new Date();
/* 取默认时长 1天 */
if(nDays == null || nDays==0){
nDays =1;
}
/* 计算过期时间 */
exprie.setTime(today.getTime()+360000*24*nDays);
/* 设置Cookie值 */
document.cookie = cookieName + "="+escape(cookieValue)+";expires=" + exprie.toGMTString();
}


function readCookie(cookieName){
/* Cookie 字符串 */
var theCookie = " " + document.cookie;
/* 找到 cookieName 的位置 */
var ind= theCookie.indexOf(cookieName);
if(ind == -1 || cookieName == ""){
return "";
}
var inde = theCookie.indexOf(";",ind);
if(inde == -1){
inde= theCookie.length;
return unescape(hteCookie.substring(ind + cookieName.length +1,inde));
}
}
posted @ 2011-11-09 16:27  wkylin  阅读(209)  评论(0编辑  收藏  举报