Javascript 设置Cookie,删除Cookie,获取Cookie 函数。
文章源自陈学虎-https://chenxuehu.com/article/2018/10/7304.html
设置Cookie:文章源自陈学虎-https://chenxuehu.com/article/2018/10/7304.html
function SetCookie(name, value) { var Days = 1; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); DelCookie(name); document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString(); }
删除Cookie:文章源自陈学虎-https://chenxuehu.com/article/2018/10/7304.html
function DelCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval=GetCookie(name); if(cval!=null) document.cookie= name + "="+cval+";path=/;expires="+exp.toGMTString(); }
获取Cookie文章源自陈学虎-https://chenxuehu.com/article/2018/10/7304.html
function GetCookie(name) { var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); if(arr != null) { return unescape(arr[2]); } return ""; }
文章源自陈学虎-https://chenxuehu.com/article/2018/10/7304.html 文章源自陈学虎-https://chenxuehu.com/article/2018/10/7304.html
评论