首页 > 代码库 > js 添加、获取、删除 cookie
js 添加、获取、删除 cookie
// 保存 Cookiefunction setCookie(name, value) { expires = new Date(); expires.setTime(expires.getTime() + (1000 * 86400 * 365)); document.cookie = name + "=" + escape(value) + ";";}// 获取 Cookiefunction getCookie(name) { cookie_name = name + "="; cookie_length = document.cookie.length; cookie_begin = 0; while (cookie_begin < cookie_length) { value_begin = cookie_begin + cookie_name.length; if (document.cookie.substring(cookie_begin, value_begin) == cookie_name) { var value_end = document.cookie.indexOf(";", value_begin); if (value_end == -1) { value_end = cookie_length; } return unescape(document.cookie.substring(value_begin, value_end)); } cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1; if (cookie_begin == 0) { break; } } return null;}// 清除 Cookiefunction delCookie(name) { var expireNow = new Date(); document.cookie = name + "=" + "; expires="+expireNow+"" + "; path=/";}
js 添加、获取、删除 cookie
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。