首页 > Web开发 > 详细

jquery获取、设置、删除cookie

时间:2018-08-01 23:08:35      阅读:119      评论:0      收藏:0      [点我收藏+]

获取cookie:

function getCookie(cname) {
             var name = cname + "=";
             var ca = document.cookie.split(‘;‘);
             for(var i=0; i<ca.length; i++) {
                 var c = ca[i];
                 while (c.charAt(0)==‘ ‘) c = c.substring(1);
                 if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
             }
             return"";
         }

设置cookie:

function setCookie(cname, cvalue, exdays) {//删除cookie
             var date = new Date();
             date.setTime(date.getTime() + (exdays*24*60*60*1000));
             var expires = "expires="+date.toUTCString();
             document.cookie = cname + "=" + cvalue + "; " + expires;
         };

删除cookie:

function clearCookie(name) { 
             setCookie(name, "", -1); 
         }

 

jquery获取、设置、删除cookie

原文:https://www.cnblogs.com/xyhero/p/9404392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!