日期:2014-05-16 浏览次数:20572 次
function getCookie(c_name) //取值
{
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1) {
c_start = c_start + c_name.length + 1;
c_end = document.cookie.indexOf("^",c_start);
if (c_end==-1)
c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function setCookie(c_name, n_value, p_name, p_value) //设置cookie
{
var days=7;
var extime = new Date();
extime.setTime(extime.getTime() + days*24*3600*1000);
document.cookie = c_name + "=" + escape(n_value) + "^" + p_name + "=" + escape(p_value) + "^;expires=" + extime.toGMTString();
console.log(document.cookie)
}
function checkCookie() //检测cookie
{
var username = getCookie('username');
var password = getCookie('password');
if (username != null && username != "" && password != null && password != "") {
alert('username'+username);
}
else {
alert('你还没有登录')
}
}