js的cookie

function getCookie(c_name)
         {
            if (document.cookie.length>0)
            {
                c_start=document.cookie.indexOf(c_name + "=");
                if (c_start!=-1)
                {
                    c_start=c_start + c_name.length+1;
                    c_end=document.cookie.indexOf(";",c_start);
                    if (c_end==-1) c_end=document.cookie.length;
                    return document.cookie.substring(c_start,c_end);
                }
            }
            return "";
        }

        function setCookie(c_name,value,expires)
        {
            var exdate=new Date();
            exdate.setTime(exdate.getTime()+expires*1000);
            document.cookie=c_name+ "=" +value+((expires==null) ? "" :             
            ";expires="+exdate.toGMTString());
        }

猜你喜欢

转载自blog.csdn.net/weixin_41111189/article/details/82221199