bs上处理cookie的javascript代码
使用在用户登陆页面,当打开页面时,调用getcookie()函数,取得上次登陆的用户名。
当点击登陆时,调用setcookie()函数,将当前用户名保存进cookie, 这样可以方便同一
用户登陆时,不必每次输入用户名。
function setCookie(cookieName,cookieValue,expires) {
if( cookieName=="" ) return;
expiringDate = "";
if( expires!=0 ) {
var exp = new Date();
var theTime = exp.getTime() + ( expires * 24 * 60 * 60 * 1000);
exp.setTime( theTime );
expiringDate = "; expires=" + exp.toGMTString();
}
document.cookie = cookieName + "=" + cookieValue + expiringDate + "; path=/";
}
function getCookie( cookieName ) {
if( document.cookie!="" ) {
thisCookie = document.cookie.split( "; " );
for( i=0;i<thisCookie.length;i++ )
if( cookieName==thisCookie[i].split("=")[0] )
return thisCookie[i].split( "=" )[1];
return;
}
}