document.cookie = ‘user=lj‘;//添加
var oDate = new Date();
oDate.setDate(oDate.getDate() + 7);
document.cookie = ‘pwd=123;expires=‘ + oDate;//设置cookie有效期
//添加cookie
function setCookie(name,value,days)
{
var oDate = new Date();
oDate.setDate(oDate.getDate() + expires);
document.cookie = name + ‘=‘ + value + ‘;expires=‘ + oDate;
}
//读取cookie
function getCookie(name)
{
var arr = document.cookie.split(‘;‘);
for (var i = 0; i < arr.length; i++) {
var arr2 = arr[i].split(‘=‘);
if (arr2[0] = name) {
return arr2[1];
}
}
}
//删除cookie
function removeCookie(name)
{
setCookie(name, 1, -1);
}
时间: 2024-10-25 17:37:23