//删除cookie function DelCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); document.cookie = name + "=; expires=" + exp.toGMTString(); } //添加cookie var addCookie = function (objName, objValue, objDays) { var str = objName + "=" + escape(objValue); if (objDays > 0) {//为0时不设定过期时间,浏览器关闭时cookie自动消失 var date = new Date(); var ms = objDays * 3600 * 1000 * 24; date.setTime(date.getTime() + ms); str += "; expires=" + date.toGMTString(); } document.cookie = str; };