Get cookie by name

前端 未结 30 2025
野的像风
野的像风 2020-11-22 03:58

I have a getter to get the value from a cookie.

Now I have 2 cookies by the name shares= and by the name obligations= .

I want to

30条回答
  •  天命终不由人
    2020-11-22 04:39

    I have done it this way. so that i get an object to access to separate the values.With this u can pass the cookie to the parent and then you can access your values by the keys like

    var cookies=getCookieVal(mycookie);
    alert(cookies.mykey);
    function getCookieVal(parent) {
                var cookievalue = $.cookie(parent).split('&');
                var obj = {};
                $.each(cookievalue, function (i, v) {
                    var key = v.substr(0, v.indexOf("="));
                    var val = v.substr(v.indexOf("=") + 1, v.length);
    
                    obj[key] = val;
    
                });
                return obj;
            }  
    

提交回复
热议问题