Jun
09
2016
js cookies 操作函数
//取cookies function getCookie(name) { var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)")); if (arr != null) return unescape(arr[2]); return null; } //设置cookies 两个参数,一个是cookie的名子,一个是值 function SetCookie(name, value, time) { var exp = new Date(); exp.setDate(exp.getDate() + time); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); } //删除cookie function delCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = getCookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); }
最活跃的读者