Home  >  Article  >  Web Front-end  >  Implementation method of obtaining specified cook information in js

Implementation method of obtaining specified cook information in js

高洛峰
高洛峰Original
2016-12-06 14:00:101261browse

Premise:

Getting cook in js is the most painful thing, because it does not save the value of the cook variable one by one, but all the variables exist together, and you can only get a certain cook by taking out the fields one by one. value.

So write a function to get the value of a certain variable:

function get_cookie(name)
    {
        var bikky = document.cookie;
        name += "=";
        var i = 0;
        while (i < bikky.length)
        {
            var offset = i + name.length;
            if (bikky.substring(i, offset) == name)
            {
                var endstr = bikky.indexOf(";", offset);
                if (endstr == -1) endstr = bikky.length;
                return unescape(bikky.substring(offset, endstr));
            }
            i = bikky.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return null;
    }

Got it, tested it myself, and it’s usable.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:jQuery Lucky WheelNext article:jQuery Lucky Wheel