如何在JavaScript中存储和检索多维数组cookie

时间:2019-07-11 02:08:34

标签: javascript

我想在Javascript中使用多维数组cookie存储和检索记录。数组列为5,如何从Cookie获取行长?

    var a;var b;var c;var d;var e;
    var createCookie = function(name, value) {
        var expires;
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
            expires = "; expires=" + date.toGMTString();
        }
        else {
            expires = "";
        }
        document.cookie = name + "=" + value + expires + "; path=/";
    }

    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 unescape(document.cookie.substring(c_start, c_end));
            }
        }
        return "";
    }
createCookie ("array["+arraylength+"][0]", a);
createCookie ("array["+arraylength+"][2]", b);
createCookie ("array["+arraylength+"][3]", c);
createCookie ("array["+arraylength+"][4]", d);
createCookie ("array["+arraylength+"][5]", e);

0 个答案:

没有答案